package com.qyer.search.model.lastminute;

import static com.qyer.commons.utils.CommonUtils.cast2Int;
import static com.qyer.commons.utils.CommonUtils.cast2String;
import static com.qyer.search.model.QyerPlace.buildCity;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.qyer.search.Constants;
import com.qyer.search.cache.mutable.MutableCaches;
import com.qyer.search.enums.TagStatus;
import com.qyer.search.enums.TagType;
import com.qyer.search.filter.AbstractFilter;
import com.qyer.search.filter.AbstractValidator;
import com.qyer.search.model.SearchParameterEntity;
import com.qyer.search.model.SearchParameterOrigin;
import com.qyer.search.model.aggregation.AggregationProduct;
import com.qyer.search.model.aggregation.AggregationRegular;
import com.qyer.search.model.aggregation.City;
import com.qyer.search.model.aggregation.Country;
import com.qyer.search.model.aggregation.Poi;
import com.qyer.search.model.aggregation.STGInfo;
import com.qyer.search.model.aggregation.SetOutPlace;
import com.qyer.search.model.aggregation.Topic;
import com.qyer.search.model.aggregation.TravelDay;
import com.qyer.search.model.aggregation.VStype;
import com.qyer.search.model.result.Type1SearchEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.nlpcn.commons.lang.util.StringUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by tangzheng on 16/7/18.
 */

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class LightZSKU extends ZSKU{

  @JsonProperty(FIELD_OUT_ID)
  private int id;
  @JsonIgnore
  private Set<Integer> type1 = new HashSet<>();
  @JsonProperty(FIELD_OUT_TYPE2)
  private Set<Integer> type2 = new HashSet<>();
  @JsonIgnore
  private int market_info;
  @JsonProperty
  String title;
  @JsonProperty
  private List<Tag> tags = new ArrayList<>(20);
  @JsonProperty(FIELD_OUT_TAGS)
  private List<String> externalizeTagNames = new ArrayList<>(tags.size());

  public LightZSKU(int id) {
    this.id = id;
  }

  public LightZSKU() {
  }

  public LightZSKU title(String title){
    this.setTitle(title);
    return this;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  @Override public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  @Override public Set<Integer> getType1() {
    return type1;
  }

  public void setType1(Set<Integer> type1) {
    this.type1 = type1;
  }

  public void addType1 (int t){
    this.type1.add(t);
  }

  public void addType2 (int t){
    this.type2.add(t);
  }
  @Override public Set<Integer> getType2() {
    return type2;
  }

  public void setType2(Set<Integer> type2) {
    this.type2 = type2;
  }

  public int getMarket_info() {
    return market_info;
  }

  public void setMarket_info(int market_info) {
    this.market_info = market_info;
  }

  public LightZSKU type1(Set<Integer> type1) {
    setType1(type1);
    return this;
  }

  public LightZSKU type1(int t) {
    if(CollectionUtils.isEmpty(type1)) {
      setType1(new HashSet<Integer>());
      addType1(t);
    }else {
      addType1(t);
    }
    return this;
  }

  public LightZSKU type2(int t) {
    if(CollectionUtils.isEmpty(type2)) {
      setType2(new HashSet<Integer>());
      addType2(t);
    }else {
      addType2(t);
    }
    return this;
  }

  public LightZSKU type2(Set<Integer> type2) {
    setType2(type2);
    return this;
  }

  public LightZSKU addTag(Tag tag) {
    this.tags.add(tag);
    return this;
  }

  public LightZSKU addExternalizedTag(Tag tag) {
    this.externalizeTagNames.add(tag.getTagName());
    return this;
  }

  public boolean forExternalize() {
    //return TagType.STANDARD.equals(this.tagType);
    return true;
  }

  public List<Tag> getTags() {
    return tags;
  }

  public void setTags(List<Tag> tags) {
    this.tags = tags;
  }

  public List<String> getExternalizeTagNames() {
    return externalizeTagNames;
  }

  public void setExternalizeTagNames(List<String> externalizeTagNames) {
    this.externalizeTagNames = externalizeTagNames;
  }

  public List<SimpleVSKU> buildVSKUS(){
    List<SimpleVSKU> simpleVSKUs = new ArrayList<>(this.type1.size());
    for(int t1:this.type1){
      simpleVSKUs.add(new SimpleVSKU(this.id, t1, 0, this.type2, market_info, title, tags, externalizeTagNames));
    }
    if(CollectionUtils.isEmpty(simpleVSKUs))
      System.out.println("buildVSKUS:"+this.id);
    return simpleVSKUs;
  }

  private static LightZSKU build(int id) {
    return new LightZSKU(id);
  }
  public static LightZSKU build(SearchParameterEntity spe, Map<String, Object> dataMap,
                                List<AbstractFilter> filters, AggregationRegular regular,
                                AggregationProduct aggregationProduct){
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }

    //System.out.println("LightZSKU build");
    int id = cast2Int(dataMap.get(FIELD_ID));
    LightZSKU lightZSKU = build(id);
    AbstractValidator validator = MutableCaches.getInstance().SKU_AVAILABILITY_VALIDATOR
      .getCacheContent();
    if (!validator.isValid(spe, id)) {
      return null;
    }
    if(filters != null) {
      for (int i = 0; i < filters.size(); i++) {
        if (!filters.get(i).isValid(dataMap, spe))
          return null;
      }
    }
    List<LightZSKU> lightZSKUs = new ArrayList<>();
    int market_info = Integer.MAX_VALUE;
    Map<Integer, Set<Integer>> vTypeMap = regular.getvTypeMap();
    Map<Integer, Set<Integer>> vTypeFilters = regular.getvTypeFilters();
    Map<Integer, Set<Integer>> vGTypeFilters = regular.getvGTypeFilters();
    String cityStr = regular.getCity();
    String countryStr = regular.getCountry();
    String continentName = regular.getContinent();
    //System.out.println("continentName:"+continentName);
    //

    lightZSKU.setMarket_info(market_info);
    String ztitle = cast2String(dataMap.get(FIELD_TITLE));
    lightZSKU.setTitle(ztitle);

    //
    int channel = regular.getChannel();
    Set<Integer> stypeChannel = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent()
                                                                          .getvStypeMap().get(channel).getS_type_set();
    Set<Integer> vtypeSet = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent()
                                                                      .getvStypeMap().get(channel).getS_type_set();
    Map<Integer,List<Integer>> neMap = MutableCaches.getInstance().Z_TAG_SNAPSHOT
      .getCacheContent().getvStypeMap().get(channel).getNegativeMap();
    Map<Integer, Integer> filterValues = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent().getFilterValues();

    Map<Integer, List<Integer>> filterValuesList = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent().getFilterValuesList();


    Set<Integer> market_tag_Set = MutableCaches.getInstance().Z_TAG_SNAPSHOT
      .getCacheContent().getvStypeMap().get(channel).getMarket_tag_Set();

    Map<String, Integer> area = MutableCaches.getInstance().AREA.getCacheContent();
    Map<String, Integer> no_t_area = MutableCaches.getInstance().NO_TRAVEL_AREA.getCacheContent();
    //获取styoe
    //System.out.println("LightZSKU build ztag");
    Set<Integer> integerSet = new HashSet<>();
    int count166 = 0;
    List<ZTag> zTagFilterList = new ArrayList<>();
    ZTag zTag;
    List<Map<String, Object>> listedData = (List<Map<String, Object>>) dataMap.get(FIELD_Z_TAGS);
    try {
      if (CollectionUtils.isNotEmpty(listedData)) {
        for (Map<String, Object> map : listedData) {
          zTag = ZTag.buildTag(map);
          if (zTag == null) {
            continue;
          }
          if (zTag.getChannel() != channel) {
            if (zTag.getChannel() != -1) {
              continue;
            }
          }
          String tag_name = zTag.getTag_name();
          int tid = zTag.getTid();
          int zchannel = zTag.getChannel();


          //stg
          if (zchannel > 0) {
            if (!vTypeMap.containsKey(tid)) {
              continue;
            } else {
              if(!lightZSKU.getType1().contains(tid)){
                lightZSKU.type1(tid);
                if (aggregationProduct != null) {
                  if (aggregationProduct.getStg_info().containsKey(tid)) {
                    aggregationProduct.getStg_info().get(tid).setName(tag_name);
                    aggregationProduct.getStg_info().get(tid).incSize();
                    if(tid == 166){
                      count166 ++;
                    }
                    //System.out.println("aggregationProduct +1");
                  } else {
                    STGInfo stgInfo = new STGInfo(1, tag_name);
                    aggregationProduct.getStg_info().put(tid, stgInfo);
                  }
                }
              }
              /*lightZSKU.type1(tid);
              if (aggregationProduct != null) {
                if (aggregationProduct.getStg_info().containsKey(tid)) {
                  aggregationProduct.getStg_info().get(tid).setName(tag_name);
                  aggregationProduct.getStg_info().get(tid).incSize();
                  if(tid == 166){
                    count166 ++;
                  }
                  //System.out.println("aggregationProduct +1");
                } else {
                  STGInfo stgInfo = new STGInfo(1, tag_name);
                  aggregationProduct.getStg_info().put(tid, stgInfo);
                }
              }*/
            }
          } else {
            zTagFilterList.add(zTag);
            //非stg
            if (vtypeSet.contains(tid)) {
              List<Integer> list = neMap.get(tid);
              for (int gt : list) {
                if (vTypeMap.containsKey(gt)) {
                  Set<Integer> set = vTypeMap.get(gt);
                  if (set.contains(tid)) {
                    lightZSKU.type2(tid);
                    if (aggregationProduct != null) {
                      if (aggregationProduct.getStg_info().containsKey(gt)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(gt);
                        if (CollectionUtils.isNotEmpty(stgInfo.getS_type())) {
                          boolean isFound = false;
                          for (VStype vStype : stgInfo.getS_type()) {
                            if (vStype.getId() == tid) {
                              isFound = true;
                              vStype.incSize();
                              break;
                            }
                          }
                          if (!isFound) {
                            VStype vStype = new VStype(tid, tag_name, 1);
                            stgInfo.getS_type().add(vStype);
                          }
                        } else {
                          VStype vStype = new VStype(tid, tag_name, 1);
                          List<VStype> stypes = new ArrayList<>();
                          stypes.add(vStype);
                          stgInfo.setS_type(stypes);
                        }
                      } else {
                        STGInfo stgInfo = new STGInfo(0, null);
                        aggregationProduct.getStg_info().put(gt, stgInfo);
                        VStype vStype = new VStype(tid, tag_name, 1);
                        List<VStype> stypes = new ArrayList<>();
                        stypes.add(vStype);
                        stgInfo.setS_type(stypes);
                      }
                    }
                  }
                }
              }
            } else {
              //运营
              if (market_tag_Set.contains(tid)) {
                lightZSKU.setMarket_info(Integer.valueOf(tag_name.trim()));
                //System.out.println("运营:" + lightZSKU.id + ":级别:" + lightZSKU.getMarket_info());
              }else {
                //zTagFilterList.add(zTag);
              }
            }
          }

        }
      } else {
        return null;
      }
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("A" + e.toString());
    }

    if(count166 > 1){
      System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++~~~~~~~~ID:"+lightZSKU.id+"~~~Size:"+count166);
    }

    if(CollectionUtils.isEmpty(lightZSKU.getType1())){
      //System.out.println("NO STG lid:" + lightZSKU.id);
      return null;
    }

    //System.out.println("LightZSKU build TAG");
    //Tag
    Tag tag;
    Set<String> countries = new HashSet<>();
    Set<String> cities = new HashSet<>();
    Set<String> continent = new HashSet<>();
    Set<Poi> pois = new HashSet<>();

    List<Map<String, Object>> listedTags = (List<Map<String, Object>>) dataMap.get(FIELD_TAGS);
    try {
      if (CollectionUtils.isNotEmpty(listedTags)) {
        for (Map<String, Object> map : listedTags) {
          tag = Tag.buildTag(map);
          if (tag == null) {
            continue;
          }
          lightZSKU.addTag(tag);
          if (tag.forExternalize()) {
            lightZSKU.addExternalizedTag(tag);
          }
          //是否目的地，是否poi
          String name = tag.getTagName();
          /*if (tag.getTagType() == TagType.CITY) {
            cities.add(name);
          } else if (tag.getTagType() == TagType.COUNTRY) {
            countries.add(name);
          } else if (tag.getTagType() == TagType.CONTINENT) {
            continent.add(name);
          } else if (TagType.POI == tag.getTagType()) {
            int tgid = tag.getId();
            pois.add(new Poi(tgid, name, 1));
          }*/

          TagStatus status = tag.getStatus();
          if(TagStatus.ENABLE == status) {
            if (tag.getTagType() == TagType.CITY) {
              /*if(area.containsKey(name)){
                if(!no_t_area.containsKey(name))
                  cities.add(name);
              }else {
                cities.add(name);
              }*/
              if(!no_t_area.containsKey(name)){
                cities.add(name);
              }
            } else if (tag.getTagType() == TagType.COUNTRY) {
              countries.add(name);
            } else if (tag.getTagType() == TagType.CONTINENT) {
              continent.add(name);
            } else if (TagType.POI == tag.getTagType()) {
              int tgid = tag.getId();
              pois.add(new Poi(tgid, name, 1));
            }
          }
        }
      }
    }catch (Exception e){
      e.printStackTrace();
      //System.out.println("B"+ e.toString());
    }
    ////////////////////////////////////////////
    ////////////////////////////////////////////
    //统计
    try {
      if (aggregationProduct != null) {
        boolean isOk = false;
        //System.out.println("聚合目的地");
        Map<String, Country> countryMap = new HashMap<>();
        Map<String, List<String>> city_country_map = MutableCaches
          .getInstance().CITY_COUNTRY_MAP_ALL.getCacheContent();
        Map<String, Integer> cityInfo = MutableCaches.getInstance().CITIES.getCacheContent();
        Map<String, Integer> countryInfo = MutableCaches.getInstance().COUNTRIES.getCacheContent();
        Map<String, String> ccMap = MutableCaches.getInstance().COUNTRY_CONTINENT_MAP
          .getCacheContent();
        Map<Integer, Set<Integer>> area_city_map = MutableCaches.getInstance().AREA_CITY_MAP.getCacheContent();

        if (StringUtils.isEmpty(countryStr)) {
          if (StringUtils.isEmpty(cityStr)) {
            List<String> cyList = new ArrayList<>(cities);
            for (String str : countries) {
              if(countryInfo.containsKey(str)) {
                int countryId = countryInfo.get(str);
                //////////////////////////////////////////////////
                if (!ccMap.containsKey(str)) {
                  //System.out.println("CCMAP MISS " + str);
                  continue;
                }
                String continentStr = ccMap.get(str);
                if (continentName != null) {
                  if (!continentStr.equals(continentName)) {
                    continue;
                  }
                }
                if (!Constants.CONTINENT_MAP.containsKey(continentStr)) {
                  //System.out.println("CONTINENT_MAP MISS " + continentStr);
                  continue;
                }
                //////////////////////////////////////////////////
                int conid = Constants.CONTINENT_MAP.get(ccMap.get(str));
                List<City> cityList = new ArrayList<>();
                Country country = new Country(countryId, str, conid, cityList, 1);
                for (int i = 0; i < cyList.size(); i++) {
                  String cityName = cyList.get(i);
                  if (city_country_map.containsKey(cityName)) {
                    List<String> countryNames = city_country_map.get(cityName);
                    if (countryNames.contains(str)) {
                      int cityId = cityInfo.get(cityName);
                      City city = new City(cityId, cityName, 1);
                      country.add(city);
                      //System.out.println("country add city:" + cityName);
                      cities.remove(cityName);
                    }
                  } else {
                    //System.out.println("NOT MATCH CITY:" + cityName);
                  }
                }
                //
                for (int tp1 : lightZSKU.type1) {
                  if (aggregationProduct.getStg_info().containsKey(tp1)) {
                    STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                    if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                      boolean isFoundCou = false;
                      List<Country> countryList = stgInfo.getCountry();
                      for (Country country1 : countryList) {
                        if (country1.equals(country)) {
                          country1.add(country);
                          isFoundCou = true;
                          break;
                        }
                      }
                      if (!isFoundCou) {
                        countryList.add(country);
                      }
                    } else {
                      List<Country> countryList = new ArrayList<>();
                      countryList.add(country);
                      stgInfo.setCountry(countryList);
                    }
                  }
                }////////////////
              }else {
                //System.out.println("国家不存在："+str);
              }
            }
            //剩余城市
            if("亚洲".equals(continentName) || StringUtils.isBlank(continentName)) {
              if (CollectionUtils.isNotEmpty(cities)) {
                //System.out.println("剩余城市:"+cities);
                int countryId = 11;
                int conId = 10;
                List<City> cityList = new ArrayList<>();
                Country country = new Country(countryId, "中国", conId, cityList, 1);
                List<String> leftCity = new ArrayList<>(cities);
                for (String str : leftCity) {
                  //System.out.println("1剩余城市:"+str);
                  if (city_country_map.containsKey(str)) {
                    List<String> countryNames = city_country_map.get(str);
                    //System.out.println("2剩余城市国家list:"+countryNames);
                    if (countryNames.contains("中国")) {
                      //System.out.println("其他城市中国成功 "+ str);
                      int a = cityInfo.get(str);
                      City city = new City(a, str, 1);
                      country.add(city);

                    }
                  }
                }

                if (country.getCity().size() > 1) {
                  for (int tp1 : lightZSKU.type1) {
                    if (aggregationProduct.getStg_info().containsKey(tp1)) {
                      STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                      if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                        boolean isFoundCou = false;
                        List<Country> countryList = stgInfo.getCountry();
                        for (Country country1 : countryList) {
                          if (country1.equals(country)) {
                            country1.add(country);
                            isFoundCou = true;
                            break;
                          }
                        }
                        if (!isFoundCou) {
                          countryList.add(country);
                        }
                      } else {
                        List<Country> countryList = new ArrayList<>();
                        countryList.add(country);
                        stgInfo.setCountry(countryList);
                      }
                    }
                  }//
                }
              }
            }
          } else {
            int cityId = cityInfo.get(cityStr);
            if(!area_city_map.containsKey(cityId)){
            //if(!"台湾".equals(cityStr)) {
              /////////////////////////////////////////////////////////////////////////////////////////////////////
              if (city_country_map.containsKey(cityStr)) {
                List<String> cnys = city_country_map.get(cityStr);
                for (String cny : cnys) {
                  if (countries.contains(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if(!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                    }
                    int countryId = countryInfo.get(cny);
                    int conid = Constants.CONTINENT_MAP.get(ccMap.get(cny));
                    Country country = new Country(countryId, cny, conid, cityList, 1);

                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  } else if ("中国".equals(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if(!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                    }
                    int countryId = 11;
                    int conid = 10;
                    Country country = new Country(countryId, cny, conid, cityList, 1);
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  }
                }
              }
              ////////////////////////////////////////////////////////////////////////////////////////////////////
            }else {

              Set<Integer> cityListSet = area_city_map.get(cityId);
              if(city_country_map.containsKey(cityStr)) {
                List<String> cnys = city_country_map.get(cityStr);
                for (String cny : cnys) {
                  if (countries.contains(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if (!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                      isOk = true;
                    }
                    int countryId = countryInfo.get(cny);
                    int conid = Constants.CONTINENT_MAP.get(ccMap.get(cny));
                    Country country = new Country(countryId, cny, conid, cityList, 1);
                    /////////////////////////////////////////////
                    for(String cityName:cities){
                      if(!cityName.equals(cityStr)) {
                        if(cityInfo.containsKey(cityName)) {
                          int Idcity = cityInfo.get(cityName);
                          if (cityListSet.contains(Idcity)) {
                            City city2 = new City(Idcity, cityName, 1);
                            cityList.add(city2);
                          }
                        }
                      }
                    }
                    //////
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                    //////
                  }else if(cny.equals("中国")){
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if (!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                      isOk = true;
                    }
                    int countryId = 11;
                    int conid = 10;
                    Country country = new Country(11, cny, 10, cityList, 1);
                    /////////////////////////////////////////////
                    for(String cityName:cities){
                      if(!cityName.equals(cityStr)) {
                        if(cityInfo.containsKey(cityName)) {
                          int Idcity = cityInfo.get(cityName);
                          if (cityListSet.contains(Idcity)) {
                            City city2 = new City(Idcity, cityName, 1);
                            cityList.add(city2);
                          }
                        }
                      }
                    }
                    //////
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  }
                }
              }
              /////////////////////////////////////////////////////////////////////////////////////////
              /*Set<String> taiwans = new HashSet<>(MutableCaches.getInstance().TAIWAN_MAP.getCacheContent());
              taiwans.remove("台湾");

              List<City> cityList = new ArrayList<>();
              int countryId = 11;
              int conid = 10;
              //boolean isFind = false;
              /////////////
              int idCityT = cityInfo.get(cityStr);
              City cityT = new City(idCityT, cityStr, 1);
              cityList.add(cityT);
              /////////////
              Country country = new Country(countryId, "中国", conid, cityList, 1);
              for(String cityName:cities){
                if(!cityName.equals("台湾")) {
                  if (taiwans.contains(cityName)) {
                    int idCity = cityInfo.get(cityName);
                    City city = new City(idCity, cityName, 1);
                    if(!no_t_area.containsKey(cityName)) {
                      cityList.add(city);
                    }
                  }
                }
              }
              /////
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for (Country country1 : countryList) {
                      if (country1.equals(country)) {
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if (!isFoundCou) {
                      countryList.add(country);
                    }
                  } else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }*/
            }
          }/////
        } else {
          int ccid = countryInfo.get(countryStr);
          int conid = Constants.CONTINENT_MAP.get(ccMap.get(countryStr));
          if (StringUtils.isEmpty(cityStr)) {
            List<City> cityList = new ArrayList<>();
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            for (String cty : cities) {
              if(!city_country_map.containsKey(cty)){
                //System.out.println("city:"+cty);
              }else {
                if(city_country_map.containsKey(cty)) {
                  List<String> couns = city_country_map.get(cty);
                  if (couns.contains(countryStr)) {
                    if (cityInfo.containsKey(cty)) {
                      City city = new City(cityInfo.get(cty), cty, 1);
                      country.add(city);
                    }
                  }
                }
              }
            }
            //
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
            //
          } else {///////////////////////////////////////////////////////////////////////////////////

            City city = new City(cityInfo.get(cityStr), cityStr, 1);
            List<City> cityList = new ArrayList<>();
            if(!no_t_area.containsKey(cityStr)) {
              cityList.add(city);
            }
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            if(area_city_map.containsKey(cityStr)){
              Set<Integer> acityIdList = area_city_map.get(cityInfo.get(cityStr));
              for(String cityName:cities){
                if(!cityName.equals(cityStr)){
                  int idC = cityInfo.get(cityName);
                  if(acityIdList.contains(idC)){
                    City cityEntity = new City(idC, cityName, 1);
                    cityList.add(cityEntity);
                  }
                }
              }
            }

            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /*City city = new City(cityInfo.get(cityStr), cityStr, 1);
            List<City> cityList = new ArrayList<>();
            if(!no_t_area.containsKey(cityStr)) {
              cityList.add(city);
            }
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            if ("台湾".equals(cityStr)) {
              Set<String> taiwans = new HashSet<>(MutableCaches.getInstance().TAIWAN_MAP.getCacheContent());
              for (String cityName : cities) {
                if (!cityName.equals("台湾")) {
                  if (taiwans.contains(cityName)) {
                    int idCity1 = cityInfo.get(cityName);
                    City city1 = new City(idCity1, cityName, 1);
                    if(!no_t_area.containsKey(cityName)) {
                      cityList.add(city1);
                    }
                  }
                }
              }
            }
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }*/
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          }
        }
        /*if(!isOk){
          System.out.println("NOT OK:" + lightZSKU.getId());
        }*/
        //poi
        for (int tp1 : lightZSKU.type1) {
          if (aggregationProduct.getStg_info().containsKey(tp1)) {
            STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
            if (CollectionUtils.isNotEmpty(stgInfo.getPoi())) {
              boolean isFoundCou = false;
              List<Poi> poiList = stgInfo.getPoi();
              List<Poi> poiList1 = new ArrayList<>(poiList);
              for (Poi poi1 : pois) {
                for (Poi poi : poiList1) {
                  if (poi1.equals(poi)) {
                    poi.add(poi1);
                    isFoundCou = true;
                    break;
                  }
                }
                if (!isFoundCou) {
                  poiList.add(poi1);
                }
              }
            }else{
              List<Poi> poiList = new ArrayList<>(pois);
              stgInfo.setPoi(poiList);
            }
          }
        }
      }
      //////////////////////////////////////////////////////
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("C"+e.toString());
    }
    //---------------------------------------------------------------------------------------------//
    try {
      if (aggregationProduct != null) {

        for(ZTag zTAG:zTagFilterList){
          String tag_name = zTAG.getTag_name();
          int tid = zTAG.getTid();
          int zchannel = zTAG.getChannel();

          //if(tid == 134)
            //System.out.println("134");
          if (filterValues.containsKey(tid)) {
            //if(tid == 134)
              //System.out.println("AA134");
            int cid = filterValues.get(tid);
            List<Integer> cidList = filterValuesList.get(tid);
            boolean isFoundSTG = false;
            boolean isCategory = false;
            for (int s : lightZSKU.type1) {
              if(vGTypeFilters.containsKey(s)) {
                Set<Integer> set = vGTypeFilters.get(s);
                for(int gf:cidList){
                  if(set.contains(gf)) {
                    isCategory = true;
                    cid = gf;
                    break;
                  }
                }
                if (isCategory) {
                  isFoundSTG = true;
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(s);
                  if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                    if (stgInfo.getTopic().containsKey(cid)) {
                      List<Topic> topics = stgInfo.getTopic().get(cid);
                      boolean isFoundTopic = false;
                      for (Topic topic : topics) {
                        if (topic.getId() == tid) {
                          topic.incSize();
                          isFoundTopic = true;
                        }
                      }
                      if (!isFoundTopic) {
                        Topic topic = new Topic(tid, tag_name, 1);
                        topics.add(topic);
                      }
                    } else {
                      Topic topic = new Topic(tid, tag_name, 1);
                      List<Topic> list = new ArrayList<>();
                      list.add(topic);
                      stgInfo.getTopic().put(cid, list);
                    }
                  } else {
                    Map<Integer, List<Topic>> topicMap = new HashMap<>();
                    List<Topic> topicList = new ArrayList<>();
                    Topic topic = new Topic(tid, tag_name, 1);
                    topicList.add(topic);
                    topicMap.put(cid, topicList);
                    stgInfo.setTopic(topicMap);
                  }
                }
              }
            }
            //是否stype筛选项
            if (!isFoundSTG) {
              for (int s : lightZSKU.type2) {
                if(vTypeFilters.containsKey(s)) {
                  Set<Integer> set = vTypeFilters.get(s);
                  for(int gf:cidList){
                    if(set.contains(gf)) {
                      isCategory = true;
                      cid = gf;
                      break;
                    }
                  }
                  if (isCategory) {
                    //获取stgId
                    List<Integer> listSTG = neMap.get(s);
                    for (int stgId : listSTG) {
                      if (vTypeMap.containsKey(stgId)) {
                        if (vTypeMap.get(stgId).contains(s)) {
                          STGInfo stgInfo = aggregationProduct.getStg_info().get(stgId);
                          if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                            Map<Integer, List<Topic>> topicMap = stgInfo.getTopic();
                            if (topicMap.containsKey(cid)) {
                              List<Topic> topics = stgInfo.getTopic().get(cid);
                              boolean isFoundTopic = false;
                              for (Topic topic : topics) {
                                if (topic.getId() == tid) {
                                  topic.incSize();
                                  isFoundTopic = true;
                                }
                              }
                              if (!isFoundTopic) {
                                Topic topic = new Topic(tid, tag_name, 1);
                                topics.add(topic);
                              }
                            } else {
                              Topic topic = new Topic(tid, tag_name, 1);
                              List<Topic> list = new ArrayList<>();
                              list.add(topic);
                              stgInfo.getTopic().put(cid, list);
                            }
                          } else {
                            Map<Integer, List<Topic>> topicMap = new HashMap<>();
                            List<Topic> topicList = new ArrayList<>();
                            Topic topic = new Topic(tid, tag_name, 1);
                            topicList.add(topic);
                            topicMap.put(cid, topicList);
                            stgInfo.setTopic(topicMap);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }

        ////////////////////////////////////////////////////////////////////////测试
        /*for (Map<String, Object> map : listedData) {
          zTag = ZTag.buildTag(map);
          if (zTag == null) {
            continue;
          }
          if (zTag.getChannel() != channel) {
            if (zTag.getChannel() != -1) {
              continue;
            }
          }
          String tag_name = zTag.getTag_name();
          int tid = zTag.getTid();
          int zchannel = zTag.getChannel();

          if(tid == 130) {
            System.out.println("tid:" + tid);
            System.out.println("lid:"+lightZSKU.getId());
          }

          if (zchannel < 0) {
            if (filterValues.containsKey(tid)) {
              if(tid == 130)
                System.out.println("ftid:"+tid);
              //筛选项
              if (aggregationProduct != null) {
                int cid = filterValues.get(tid);
                boolean isFoundSTG = false;
                for (int s : lightZSKU.type1) {
                  if(vGTypeFilters.containsKey(s)) {
                    Set<Integer> set = vGTypeFilters.get(s);
                    if(lightZSKU.getId() == 72935){
                      System.out.println("cid:"+cid+"vGTypeFilters:"+set);
                    }
                    if (set.contains(cid)) {
                      isFoundSTG = true;
                      STGInfo stgInfo = aggregationProduct.getStg_info().get(s);
                      if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                        if (stgInfo.getTopic().containsKey(cid)) {
                          List<Topic> topics = stgInfo.getTopic().get(cid);
                          boolean isFoundTopic = false;
                          for (Topic topic : topics) {
                            if (topic.getId() == tid) {
                              topic.incSize();
                              isFoundTopic = true;
                            }
                          }
                          if (!isFoundTopic) {
                            Topic topic = new Topic(tid, tag_name, 1);
                            topics.add(topic);
                          }
                        } else {
                          Topic topic = new Topic(tid, tag_name, 1);
                          List<Topic> list = new ArrayList<>();
                          list.add(topic);
                          stgInfo.getTopic().put(cid, list);
                        }
                      } else {
                        Map<Integer, List<Topic>> topicMap = new HashMap<>();
                        List<Topic> topicList = new ArrayList<>();
                        Topic topic = new Topic(tid, tag_name, 1);
                        topicList.add(topic);
                        topicMap.put(cid, topicList);
                        stgInfo.setTopic(topicMap);
                      }
                    }
                  }
                }
                //是否stype筛选项
                if (!isFoundSTG) {
                  for (int s : lightZSKU.type2) {
                    if(vTypeFilters.containsKey(s)) {
                      Set<Integer> set = vTypeFilters.get(s);
                      if(lightZSKU.getId() == 72935){
                        System.out.println("cid:"+cid+"vTypeFilters:"+set);
                      }
                      if (set.contains(cid)) {
                        //获取stgId
                        List<Integer> listSTG = neMap.get(s);
                        for (int stgId : listSTG) {
                          if (vTypeMap.containsKey(stgId)) {
                            if (vTypeMap.get(stgId).contains(s)) {
                              STGInfo stgInfo = aggregationProduct.getStg_info().get(stgId);
                              if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                                Map<Integer, List<Topic>> topicMap = stgInfo.getTopic();
                                if (topicMap.containsKey(cid)) {
                                  List<Topic> topics = stgInfo.getTopic().get(cid);
                                  boolean isFoundTopic = false;
                                  for (Topic topic : topics) {
                                    if (topic.getId() == tid) {
                                      topic.incSize();
                                      isFoundTopic = true;
                                    }
                                  }
                                  if (!isFoundTopic) {
                                    Topic topic = new Topic(tid, tag_name, 1);
                                    topics.add(topic);
                                  }
                                } else {
                                  Topic topic = new Topic(tid, tag_name, 1);
                                  List<Topic> list = new ArrayList<>();
                                  list.add(topic);
                                  stgInfo.getTopic().put(cid, list);
                                }
                              } else {
                                Map<Integer, List<Topic>> topicMap = new HashMap<>();
                                List<Topic> topicList = new ArrayList<>();
                                Topic topic = new Topic(tid, tag_name, 1);
                                topicList.add(topic);
                                topicMap.put(cid, topicList);
                                stgInfo.setTopic(topicMap);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }///////////////////
            }
          }
        }*/
        ////////////////////////////////////////////////////////////////////测试////////////////////////
        //统计国家城市，poi
      /*
      Tag tag;
      Set<String> countries = new HashSet<>();
      Set<String> cities = new HashSet<>();
      Set<String> continent = new HashSet<>();
      List<Poi> pois = new ArrayList<>();

      List<Map<String, Object>> listedTags = (List<Map<String, Object>>) dataMap.get(FIELD_TAGS);
      if (CollectionUtils.isNotEmpty(listedTags)) {
        for (Map<String, Object> map : listedTags) {
          tag = Tag.buildTag(map);
          if (tag == null) {
            continue;
          }
          //是否目的地，是否poi
          String name = tag.getTagName();
          if(tag.getTagType() == TagType.CITY){
            cities.add(name);
          }else if(tag.getTagType() == TagType.COUNTRY){
            countries.add(name);
          }else if(tag.getTagType() == TagType.CONTINENT){
            continent.add(name);
          }else if(TagType.POI == tag.getTagType()){
            int tgid = tag.getId();
            pois.add(new Poi(tgid, name, 1));
          }
        }
      }
      //统计
      Map<String, Country> countryMap = new HashMap<>();
      Map<String,List<String>> city_country_map = MutableCaches.getInstance().CITY_COUNTRY_MAP_ALL.getCacheContent();
      Map<String,Integer> cityInfo = MutableCaches.getInstance().CITIES.getCacheContent();
      Map<String,Integer> countryInfo = MutableCaches.getInstance().COUNTRIES.getCacheContent();
      Map<String,String> ccMap = MutableCaches.getInstance().COUNTRY_CONTINENT_MAP.getCacheContent();

      if(StringUtils.isEmpty(countryStr)){
        if(StringUtils.isEmpty(cityStr)){
          List<String> cyList = new ArrayList<>(cities);
          for(String str:countries){
            int countryId = countryInfo.get(str);
            int conid = Constants.CONTINENT_MAP.get(ccMap.get(str));
            List<City> cityList = new ArrayList<>();
            Country country = new Country(countryId, str, conid, cityList, 1);
            for(int i = 0; i < cyList.size(); i++){
              String cityName = cyList.get(i);
              List<String> countryNames = city_country_map.get(cityName);
              if(countryNames.contains(str)){
                int cityId = cityInfo.get(cityName);
                City city = new City(cityId, cityName, 1);
                country.add(city);
                cities.remove(cityName);
              }
            }
            //
            for(int tp1:lightZSKU.type1){
              if(aggregationProduct.getStg_info().containsKey(tp1)){
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for(Country country1:countryList){
                    if(country1.equals(country)){
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if(!isFoundCou){
                    countryList.add(country);
                  }
                }else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
          //剩余城市
          if(CollectionUtils.isNotEmpty(cities)){

            int countryId = 11;
            int conId = 10;
            List<City> cityList = new ArrayList<>();
            Country country = new Country(countryId, "中国", conId, cityList, 1);

            for(String str:cities){
              List<String> countryNames = city_country_map.get(str);
              if(countryNames.contains("中国")){
                int a = cityInfo.get(str);
                City city = new City(a, str, 1);
                country.add(city);
                continue;
              }
            }

            for(int tp1:lightZSKU.type1){
              if(aggregationProduct.getStg_info().containsKey(tp1)){
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for(Country country1:countryList){
                    if(country1.equals(country)){
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if(!isFoundCou){
                    countryList.add(country);
                  }
                }else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
        }else {
          int cityId = cityInfo.get(cityStr);
          List<String> cnys = city_country_map.get(cityStr);
          for(String cny:cnys){
            if(countries.contains(cny)){
              City city = new City(cityId, cityStr, 1);
              List<City> cityList = new ArrayList<>();
              int countryId = countryInfo.get(cny);
              int conid = Constants.CONTINENT_MAP
                .get(ccMap.get(cny));
              Country country = new Country(countryId, cny, conid, cityList, 1);

              for(int tp1:lightZSKU.type1){
                if(aggregationProduct.getStg_info().containsKey(tp1)){
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for(Country country1:countryList){
                      if(country1.equals(country)){
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if(!isFoundCou){
                      countryList.add(country);
                    }
                  }else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }else if("中国".equals(cny)){
              City city = new City(cityId, cityStr, 1);
              List<City> cityList = new ArrayList<>();
              int countryId = 11;
              int conid = 10;
              Country country = new Country(countryId, cny, conid, cityList, 1);
              for(int tp1:lightZSKU.type1){
                if(aggregationProduct.getStg_info().containsKey(tp1)){
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for(Country country1:countryList){
                      if(country1.equals(country)){
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if(!isFoundCou){
                      countryList.add(country);
                    }
                  }else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }
          }
        }
      }else {
        int ccid = countryInfo.get(countryStr);
        int conid = Constants.CONTINENT_MAP
          .get(ccMap.get(countryStr));
        if(StringUtils.isEmpty(cityStr)){
          List<City> cityList = new ArrayList<>();
          Country country = new Country(ccid, countryStr, conid, cityList, 1);
          for(String cty:cities){
            List<String> couns = city_country_map.get(cty);
            if(couns.contains(countryStr)){
              City city = new City(cityInfo.get(cty), cty, 1);
              country.add(city);
            }
          }
          //
          for(int tp1:lightZSKU.type1){
            if(aggregationProduct.getStg_info().containsKey(tp1)){
              STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
              if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                boolean isFoundCou = false;
                List<Country> countryList = stgInfo.getCountry();
                for(Country country1:countryList){
                  if(country1.equals(country)){
                    country1.add(country);
                    isFoundCou = true;
                    break;
                  }
                }
                if(!isFoundCou){
                  countryList.add(country);
                }
              }else {
                List<Country> countryList = new ArrayList<>();
                countryList.add(country);
                stgInfo.setCountry(countryList);
              }
            }
          }
          //
        }else {
          City city = new City(cityInfo.get(cityStr), cityStr, 1);
          List<City> cityList = new ArrayList<>();
          Country country = new Country(ccid, countryStr, conid, cityList,1);
          for(int tp1:lightZSKU.type1){
            if(aggregationProduct.getStg_info().containsKey(tp1)){
              STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
              if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                boolean isFoundCou = false;
                List<Country> countryList = stgInfo.getCountry();
                for(Country country1:countryList){
                  if(country1.equals(country)){
                    country1.add(country);
                    isFoundCou = true;
                    break;
                  }
                }
                if(!isFoundCou){
                  countryList.add(country);
                }
              }else {
                List<Country> countryList = new ArrayList<>();
                countryList.add(country);
                stgInfo.setCountry(countryList);
              }
            }
          }
        }
      }*/
        //start_city_id
        try {
          List<Map<String, Object>> listedCity = (List<Map<String, Object>>) dataMap
            .get(FIELD_CITIES);
          if (CollectionUtils.isNotEmpty(listedCity)) {
            //System.out.println("START_CITY for lid:" + lightZSKU.id);
            for (Map<String, Object> map : listedCity) {
              com.qyer.search.model.City city = com.qyer.search.model.City.buildCity(map);
              City newCity = new City(city.getId(), city.getPlaceName(), 1);
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  List<City> cityList = stgInfo.getStart_city_id();
                  if (CollectionUtils.isNotEmpty(cityList)) {
                    boolean isFound = false;
                    for (City city1 : cityList) {
                      if (city1.equals(newCity)) {
                        city1.add(newCity);
                        isFound = true;
                        break;
                      }
                    }
                    if (!isFound) {
                      cityList.add(newCity);
                    }
                  } else {
                    List<City> list = new ArrayList<>();
                    list.add(newCity);
                    stgInfo.setStart_city_id(list);
                  }
                }
              }
            }
          }
        }catch (Exception e){
          e.printStackTrace();
          System.out.println(e.toString());
        }
        //travelday
        //System.out.println("LightZSKU build day");
        try {
          int day = cast2Int(dataMap.get(FIELD_TRAVELDAY));
          if (day > 0) {
            TravelDay travelDay = new TravelDay(day, 1);
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                List<TravelDay> travelDays = stgInfo.getTravelDays();
                if (CollectionUtils.isNotEmpty(travelDays)) {
                  boolean isFound = false;
                  for (TravelDay td : travelDays) {
                    if (td.equals(travelDay)) {
                      td.add(travelDay);
                      isFound = true;
                      break;
                    }
                  }
                  if (!isFound) {
                    travelDays.add(travelDay);
                  }
                } else {
                  List<TravelDay> list = new ArrayList<>();
                  list.add(travelDay);
                  stgInfo.setTravelDays(list);
                }
              }
            }
          }
        }catch (Exception e){
          e.printStackTrace();
          System.out.println("E"+e.toString());
        }
        //abroad
        //System.out.println("FIELD_SOURCE_PLACE go");
        List<Map<String, Object>> listedAbroad = (List<Map<String, Object>>) dataMap
          .get(FIELD_SOURCE_PLACE);
        if (CollectionUtils.isNotEmpty(listedAbroad)) {
          //System.out.println("FIELD_SOURCE_PLACE");
          for (Map<String, Object> map : listedAbroad) {
            com.qyer.search.model.SetOutPlace setOutPlace = com.qyer.search.model.SetOutPlace
              .buildPlace(map);
            SetOutPlace setOutPlace1 = new SetOutPlace(Constants.START_POS_MAP_INVERS_NAME
                                                         .get(setOutPlace
                                                                .getId()), setOutPlace.getPlace(), 1);
            //System.out.println("SETOUT"+setOutPlace1.toString());
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                List<SetOutPlace> cityList = stgInfo.getAbroad();
                if (CollectionUtils.isNotEmpty(cityList)) {
                  boolean isFound = false;
                  for (SetOutPlace city1 : cityList) {
                    if (city1.equals(setOutPlace1)) {
                      city1.add(setOutPlace1);
                      isFound = true;
                      break;
                    }
                  }
                  if (!isFound) {
                    cityList.add(setOutPlace1);
                  }
                } else {
                  List<SetOutPlace> list = new ArrayList<>();
                  list.add(setOutPlace1);
                  stgInfo.setAbroad(list);
                }
              }
            }
          }
        }else {
          //System.out.println("set out place null id :" + lightZSKU.id);
        }
        //title
        //System.out.println("JIOOIPPDA");
      }
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("D"+e.toString());
    }
    return lightZSKU;
  }



  public static LightZSKU buildNew(SearchParameterEntity spe, Map<String, Object> dataMap,
                                List<AbstractFilter> filters, AggregationRegular regular,
                                AggregationProduct aggregationProduct){
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }

    //System.out.println("LightZSKU build");
    int id = cast2Int(dataMap.get(FIELD_ID));
    LightZSKU lightZSKU = build(id);
    AbstractValidator validator = MutableCaches.getInstance().SKU_AVAILABILITY_VALIDATOR
      .getCacheContent();
    if (!validator.isValid(spe, id)) {
      return null;
    }
    if(filters != null) {
      for (int i = 0; i < filters.size(); i++) {
        if (!filters.get(i).isValid(dataMap, spe))
          return null;
      }
    }
    List<LightZSKU> lightZSKUs = new ArrayList<>();
    int market_info = Integer.MAX_VALUE;
    Map<Integer, Set<Integer>> vTypeMap = regular.getvTypeMap();
    Map<Integer, Set<Integer>> vTypeFilters = regular.getvTypeFilters();
    Map<Integer, Set<Integer>> vGTypeFilters = regular.getvGTypeFilters();
    String cityStr = regular.getCity();
    String countryStr = regular.getCountry();
    String continentName = regular.getContinent();
    //System.out.println("continentName:"+continentName);
    //

    lightZSKU.setMarket_info(market_info);
    String ztitle = cast2String(dataMap.get(FIELD_TITLE));
    lightZSKU.setTitle(ztitle);

    //
    int channel = regular.getChannel();
    Set<Integer> stypeChannel = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent()
                                                                          .getvStypeMap().get(channel).getS_type_set();
    Set<Integer> vtypeSet = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent()
                                                                      .getvStypeMap().get(channel).getS_type_set();
    Map<Integer,List<Integer>> neMap = MutableCaches.getInstance().Z_TAG_SNAPSHOT
      .getCacheContent().getvStypeMap().get(channel).getNegativeMap();
    Map<Integer, Integer> filterValues = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent().getFilterValues();
    Set<Integer> market_tag_Set = MutableCaches.getInstance().Z_TAG_SNAPSHOT
      .getCacheContent().getvStypeMap().get(channel).getMarket_tag_Set();

    Map<String, Integer> area = MutableCaches.getInstance().AREA.getCacheContent();
    Map<String, Integer> no_t_area = MutableCaches.getInstance().NO_TRAVEL_AREA.getCacheContent();
    //获取styoe
    //System.out.println("LightZSKU build ztag");
    Set<Integer> integerSet = new HashSet<>();
    int count166 = 0;
    ZTag zTag;
    List<Map<String, Object>> listedData = (List<Map<String, Object>>) dataMap.get(FIELD_Z_TAGS);
    try {
      if (CollectionUtils.isNotEmpty(listedData)) {
        for (Map<String, Object> map : listedData) {
          zTag = ZTag.buildTag(map);
          if (zTag == null) {
            continue;
          }
          if (zTag.getChannel() != channel) {
            if (zTag.getChannel() != -1) {
              continue;
            }
          }
          String tag_name = zTag.getTag_name();
          int tid = zTag.getTid();
          int zchannel = zTag.getChannel();


          //stg
          if (zchannel > 0) {
            if (!vTypeMap.containsKey(tid)) {
              continue;
            } else {
              if(!lightZSKU.getType1().contains(tid)){
                lightZSKU.type1(tid);
                if (aggregationProduct != null) {
                  if (aggregationProduct.getStg_info().containsKey(tid)) {
                    aggregationProduct.getStg_info().get(tid).setName(tag_name);
                    aggregationProduct.getStg_info().get(tid).incSize();
                    if(tid == 166){
                      count166 ++;
                    }
                    //System.out.println("aggregationProduct +1");
                  } else {
                    STGInfo stgInfo = new STGInfo(1, tag_name);
                    aggregationProduct.getStg_info().put(tid, stgInfo);
                  }
                }
              }
              /*lightZSKU.type1(tid);
              if (aggregationProduct != null) {
                if (aggregationProduct.getStg_info().containsKey(tid)) {
                  aggregationProduct.getStg_info().get(tid).setName(tag_name);
                  aggregationProduct.getStg_info().get(tid).incSize();
                  if(tid == 166){
                    count166 ++;
                  }
                  //System.out.println("aggregationProduct +1");
                } else {
                  STGInfo stgInfo = new STGInfo(1, tag_name);
                  aggregationProduct.getStg_info().put(tid, stgInfo);
                }
              }*/
            }
          } else {
            //非stg
            if (vtypeSet.contains(tid)) {
              List<Integer> list = neMap.get(tid);
              for (int gt : list) {
                if (vTypeMap.containsKey(gt)) {
                  Set<Integer> set = vTypeMap.get(gt);
                  if (set.contains(tid)) {
                    lightZSKU.type2(tid);
                    if (aggregationProduct != null) {
                      if (aggregationProduct.getStg_info().containsKey(gt)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(gt);
                        if (CollectionUtils.isNotEmpty(stgInfo.getS_type())) {
                          boolean isFound = false;
                          for (VStype vStype : stgInfo.getS_type()) {
                            if (vStype.getId() == tid) {
                              isFound = true;
                              vStype.incSize();
                              break;
                            }
                          }
                          if (!isFound) {
                            VStype vStype = new VStype(tid, tag_name, 1);
                            stgInfo.getS_type().add(vStype);
                          }
                        } else {
                          VStype vStype = new VStype(tid, tag_name, 1);
                          List<VStype> stypes = new ArrayList<>();
                          stypes.add(vStype);
                          stgInfo.setS_type(stypes);
                        }
                      } else {
                        STGInfo stgInfo = new STGInfo(0, null);
                        aggregationProduct.getStg_info().put(gt, stgInfo);
                        VStype vStype = new VStype(tid, tag_name, 1);
                        List<VStype> stypes = new ArrayList<>();
                        stypes.add(vStype);
                        stgInfo.setS_type(stypes);
                      }
                    }
                  }
                }
              }
            } else {
              //运营
              if (market_tag_Set.contains(tid)) {
                lightZSKU.setMarket_info(Integer.valueOf(tag_name.trim()));
                //System.out.println("运营:" + lightZSKU.id + ":级别:" + lightZSKU.getMarket_info());
              }
            }
          }

        }
      } else {
        return null;
      }
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("A" + e.toString());
    }

    if(count166 > 1){
      System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++~~~~~~~~ID:"+lightZSKU.id+"~~~Size:"+count166);
    }

    if(CollectionUtils.isEmpty(lightZSKU.getType1())){
      //System.out.println("NO STG lid:" + lightZSKU.id);
      return null;
    }

    //System.out.println("LightZSKU build TAG");
    //Tag
    Tag tag;
    Set<String> countries = new HashSet<>();
    Set<String> cities = new HashSet<>();
    Set<String> continent = new HashSet<>();
    Set<Poi> pois = new HashSet<>();

    List<Map<String, Object>> listedTags = (List<Map<String, Object>>) dataMap.get(FIELD_TAGS);
    try {
      if (CollectionUtils.isNotEmpty(listedTags)) {
        for (Map<String, Object> map : listedTags) {
          tag = Tag.buildTag(map);
          if (tag == null) {
            continue;
          }
          lightZSKU.addTag(tag);
          if (tag.forExternalize()) {
            lightZSKU.addExternalizedTag(tag);
          }
          //是否目的地，是否poi
          String name = tag.getTagName();
          /*if (tag.getTagType() == TagType.CITY) {
            cities.add(name);
          } else if (tag.getTagType() == TagType.COUNTRY) {
            countries.add(name);
          } else if (tag.getTagType() == TagType.CONTINENT) {
            continent.add(name);
          } else if (TagType.POI == tag.getTagType()) {
            int tgid = tag.getId();
            pois.add(new Poi(tgid, name, 1));
          }*/

          TagStatus status = tag.getStatus();
          if(TagStatus.ENABLE == status) {
            if (tag.getTagType() == TagType.CITY) {
              /*if(area.containsKey(name)){
                if(!no_t_area.containsKey(name))
                  cities.add(name);
              }else {
                cities.add(name);
              }*/
              if(!no_t_area.containsKey(name)){
                cities.add(name);
              }
            } else if (tag.getTagType() == TagType.COUNTRY) {
              countries.add(name);
            } else if (tag.getTagType() == TagType.CONTINENT) {
              continent.add(name);
            } else if (TagType.POI == tag.getTagType()) {
              int tgid = tag.getId();
              pois.add(new Poi(tgid, name, 1));
            }
          }
        }
      }
    }catch (Exception e){
      e.printStackTrace();
      //System.out.println("B"+ e.toString());
    }
    ////////////////////////////////////////////
    ////////////////////////////////////////////
    //统计
    try {
      if (aggregationProduct != null) {
        boolean isOk = false;
        //System.out.println("聚合目的地");
        Map<String, Country> countryMap = new HashMap<>();
        Map<String, List<String>> city_country_map = MutableCaches
          .getInstance().CITY_COUNTRY_MAP_ALL.getCacheContent();
        Map<String, Integer> cityInfo = MutableCaches.getInstance().CITIES.getCacheContent();
        Map<String, Integer> countryInfo = MutableCaches.getInstance().COUNTRIES.getCacheContent();
        Map<String, String> ccMap = MutableCaches.getInstance().COUNTRY_CONTINENT_MAP
          .getCacheContent();
        Map<Integer, Set<Integer>> area_city_map = MutableCaches.getInstance().AREA_CITY_MAP.getCacheContent();

        if (StringUtils.isEmpty(countryStr)) {
          if (StringUtils.isEmpty(cityStr)) {
            List<String> cyList = new ArrayList<>(cities);
            for (String str : countries) {
              if(countryInfo.containsKey(str)) {
                int countryId = countryInfo.get(str);
                //////////////////////////////////////////////////
                if (!ccMap.containsKey(str)) {
                  //System.out.println("CCMAP MISS " + str);
                  continue;
                }
                String continentStr = ccMap.get(str);
                if (continentName != null) {
                  if (!continentStr.equals(continentName)) {
                    continue;
                  }
                }
                if (!Constants.CONTINENT_MAP.containsKey(continentStr)) {
                  //System.out.println("CONTINENT_MAP MISS " + continentStr);
                  continue;
                }
                //////////////////////////////////////////////////
                int conid = Constants.CONTINENT_MAP.get(ccMap.get(str));
                List<City> cityList = new ArrayList<>();
                Country country = new Country(countryId, str, conid, cityList, 1);
                for (int i = 0; i < cyList.size(); i++) {
                  String cityName = cyList.get(i);
                  if (city_country_map.containsKey(cityName)) {
                    List<String> countryNames = city_country_map.get(cityName);
                    if (countryNames.contains(str)) {
                      int cityId = cityInfo.get(cityName);
                      City city = new City(cityId, cityName, 1);
                      country.add(city);
                      //System.out.println("country add city:" + cityName);
                      cities.remove(cityName);
                    }
                  } else {
                    //System.out.println("NOT MATCH CITY:" + cityName);
                  }
                }
                //
                for (int tp1 : lightZSKU.type1) {
                  if (aggregationProduct.getStg_info().containsKey(tp1)) {
                    STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                    if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                      boolean isFoundCou = false;
                      List<Country> countryList = stgInfo.getCountry();
                      for (Country country1 : countryList) {
                        if (country1.equals(country)) {
                          country1.add(country);
                          isFoundCou = true;
                          break;
                        }
                      }
                      if (!isFoundCou) {
                        countryList.add(country);
                      }
                    } else {
                      List<Country> countryList = new ArrayList<>();
                      countryList.add(country);
                      stgInfo.setCountry(countryList);
                    }
                  }
                }////////////////
              }else {
                //System.out.println("国家不存在："+str);
              }
            }
            //剩余城市
            if("亚洲".equals(continentName) || StringUtils.isBlank(continentName)) {
              if (CollectionUtils.isNotEmpty(cities)) {
                //System.out.println("剩余城市:"+cities);
                int countryId = 11;
                int conId = 10;
                List<City> cityList = new ArrayList<>();
                Country country = new Country(countryId, "中国", conId, cityList, 1);
                List<String> leftCity = new ArrayList<>(cities);
                for (String str : leftCity) {
                  //System.out.println("1剩余城市:"+str);
                  if (city_country_map.containsKey(str)) {
                    List<String> countryNames = city_country_map.get(str);
                    //System.out.println("2剩余城市国家list:"+countryNames);
                    if (countryNames.contains("中国")) {
                      //System.out.println("其他城市中国成功 "+ str);
                      int a = cityInfo.get(str);
                      City city = new City(a, str, 1);
                      country.add(city);

                    }
                  }
                }

                if (country.getCity().size() > 1) {
                  for (int tp1 : lightZSKU.type1) {
                    if (aggregationProduct.getStg_info().containsKey(tp1)) {
                      STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                      if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                        boolean isFoundCou = false;
                        List<Country> countryList = stgInfo.getCountry();
                        for (Country country1 : countryList) {
                          if (country1.equals(country)) {
                            country1.add(country);
                            isFoundCou = true;
                            break;
                          }
                        }
                        if (!isFoundCou) {
                          countryList.add(country);
                        }
                      } else {
                        List<Country> countryList = new ArrayList<>();
                        countryList.add(country);
                        stgInfo.setCountry(countryList);
                      }
                    }
                  }//
                }
              }
            }
          } else {
            int cityId = cityInfo.get(cityStr);
            if(!area_city_map.containsKey(cityId)){
              //if(!"台湾".equals(cityStr)) {
              /////////////////////////////////////////////////////////////////////////////////////////////////////
              if (city_country_map.containsKey(cityStr)) {
                List<String> cnys = city_country_map.get(cityStr);
                for (String cny : cnys) {
                  if (countries.contains(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if(!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                    }
                    int countryId = countryInfo.get(cny);
                    int conid = Constants.CONTINENT_MAP.get(ccMap.get(cny));
                    Country country = new Country(countryId, cny, conid, cityList, 1);

                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  } else if ("中国".equals(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if(!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                    }
                    int countryId = 11;
                    int conid = 10;
                    Country country = new Country(countryId, cny, conid, cityList, 1);
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  }
                }
              }
              ////////////////////////////////////////////////////////////////////////////////////////////////////
            }else {

              Set<Integer> cityListSet = area_city_map.get(cityId);
              if(city_country_map.containsKey(cityStr)) {
                List<String> cnys = city_country_map.get(cityStr);
                for (String cny : cnys) {
                  if (countries.contains(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if (!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                      isOk = true;
                    }
                    int countryId = countryInfo.get(cny);
                    int conid = Constants.CONTINENT_MAP.get(ccMap.get(cny));
                    Country country = new Country(countryId, cny, conid, cityList, 1);
                    /////////////////////////////////////////////
                    for(String cityName:cities){
                      if(!cityName.equals(cityStr)) {
                        if(cityInfo.containsKey(cityName)) {
                          int Idcity = cityInfo.get(cityName);
                          if (cityListSet.contains(Idcity)) {
                            City city2 = new City(Idcity, cityName, 1);
                            cityList.add(city2);
                          }
                        }
                      }
                    }
                    //////
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                    //////
                  }else if(cny.equals("中国")){
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    if (!no_t_area.containsKey(cityStr)) {
                      cityList.add(city);
                      isOk = true;
                    }
                    int countryId = 11;
                    int conid = 10;
                    Country country = new Country(11, cny, 10, cityList, 1);
                    /////////////////////////////////////////////
                    for(String cityName:cities){
                      if(!cityName.equals(cityStr)) {
                        if(cityInfo.containsKey(cityName)) {
                          int Idcity = cityInfo.get(cityName);
                          if (cityListSet.contains(Idcity)) {
                            City city2 = new City(Idcity, cityName, 1);
                            cityList.add(city2);
                          }
                        }
                      }
                    }
                    //////
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  }
                }
              }
              /////////////////////////////////////////////////////////////////////////////////////////
              /*Set<String> taiwans = new HashSet<>(MutableCaches.getInstance().TAIWAN_MAP.getCacheContent());
              taiwans.remove("台湾");

              List<City> cityList = new ArrayList<>();
              int countryId = 11;
              int conid = 10;
              //boolean isFind = false;
              /////////////
              int idCityT = cityInfo.get(cityStr);
              City cityT = new City(idCityT, cityStr, 1);
              cityList.add(cityT);
              /////////////
              Country country = new Country(countryId, "中国", conid, cityList, 1);
              for(String cityName:cities){
                if(!cityName.equals("台湾")) {
                  if (taiwans.contains(cityName)) {
                    int idCity = cityInfo.get(cityName);
                    City city = new City(idCity, cityName, 1);
                    if(!no_t_area.containsKey(cityName)) {
                      cityList.add(city);
                    }
                  }
                }
              }
              /////
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for (Country country1 : countryList) {
                      if (country1.equals(country)) {
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if (!isFoundCou) {
                      countryList.add(country);
                    }
                  } else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }*/
            }
          }/////
        } else {
          int ccid = countryInfo.get(countryStr);
          int conid = Constants.CONTINENT_MAP.get(ccMap.get(countryStr));
          if (StringUtils.isEmpty(cityStr)) {
            List<City> cityList = new ArrayList<>();
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            for (String cty : cities) {
              if(!city_country_map.containsKey(cty)){
                //System.out.println("city:"+cty);
              }else {
                if(city_country_map.containsKey(cty)) {
                  List<String> couns = city_country_map.get(cty);
                  if (couns.contains(countryStr)) {
                    if (cityInfo.containsKey(cty)) {
                      City city = new City(cityInfo.get(cty), cty, 1);
                      country.add(city);
                    }
                  }
                }
              }
            }
            //
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
            //
          } else {///////////////////////////////////////////////////////////////////////////////////

            City city = new City(cityInfo.get(cityStr), cityStr, 1);
            List<City> cityList = new ArrayList<>();
            if(!no_t_area.containsKey(cityStr)) {
              cityList.add(city);
            }
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            if(area_city_map.containsKey(cityStr)){
              Set<Integer> acityIdList = area_city_map.get(cityInfo.get(cityStr));
              for(String cityName:cities){
                if(!cityName.equals(cityStr)){
                  int idC = cityInfo.get(cityName);
                  if(acityIdList.contains(idC)){
                    City cityEntity = new City(idC, cityName, 1);
                    cityList.add(cityEntity);
                  }
                }
              }
            }

            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /*City city = new City(cityInfo.get(cityStr), cityStr, 1);
            List<City> cityList = new ArrayList<>();
            if(!no_t_area.containsKey(cityStr)) {
              cityList.add(city);
            }
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            if ("台湾".equals(cityStr)) {
              Set<String> taiwans = new HashSet<>(MutableCaches.getInstance().TAIWAN_MAP.getCacheContent());
              for (String cityName : cities) {
                if (!cityName.equals("台湾")) {
                  if (taiwans.contains(cityName)) {
                    int idCity1 = cityInfo.get(cityName);
                    City city1 = new City(idCity1, cityName, 1);
                    if(!no_t_area.containsKey(cityName)) {
                      cityList.add(city1);
                    }
                  }
                }
              }
            }
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }*/
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          }
        }
        /*if(!isOk){
          System.out.println("NOT OK:" + lightZSKU.getId());
        }*/
        //poi
        for (int tp1 : lightZSKU.type1) {
          if (aggregationProduct.getStg_info().containsKey(tp1)) {
            STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
            if (CollectionUtils.isNotEmpty(stgInfo.getPoi())) {
              boolean isFoundCou = false;
              List<Poi> poiList = stgInfo.getPoi();
              List<Poi> poiList1 = new ArrayList<>(poiList);
              for (Poi poi1 : pois) {
                for (Poi poi : poiList1) {
                  if (poi1.equals(poi)) {
                    poi.add(poi1);
                    isFoundCou = true;
                    break;
                  }
                }
                if (!isFoundCou) {
                  poiList.add(poi1);
                }
              }
            }else{
              List<Poi> poiList = new ArrayList<>(pois);
              stgInfo.setPoi(poiList);
            }
          }
        }
      }
      //////////////////////////////////////////////////////
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("C"+e.toString());
    }
    //---------------------------------------------------------------------------------------------//
    try {
      if (aggregationProduct != null) {
        for (Map<String, Object> map : listedData) {
          zTag = ZTag.buildTag(map);
          if (zTag == null) {
            continue;
          }
          if (zTag.getChannel() != channel) {
            if (zTag.getChannel() != -1) {
              continue;
            }
          }
          String tag_name = zTag.getTag_name();
          int tid = zTag.getTid();
          int zchannel = zTag.getChannel();

          if (zchannel < 0) {
            if (filterValues.containsKey(tid)) {
              //筛选项
              if (aggregationProduct != null) {
                int cid = filterValues.get(tid);
                boolean isFoundSTG = false;
                for (int s : lightZSKU.type1) {
                  if(vGTypeFilters.containsKey(s)) {
                    Set<Integer> set = vGTypeFilters.get(s);
                    if (set.contains(cid)) {
                      isFoundSTG = true;
                      STGInfo stgInfo = aggregationProduct.getStg_info().get(s);
                      if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                        if (stgInfo.getTopic().containsKey(cid)) {
                          List<Topic> topics = stgInfo.getTopic().get(cid);
                          boolean isFoundTopic = false;
                          for (Topic topic : topics) {
                            if (topic.getId() == tid) {
                              topic.incSize();
                              isFoundTopic = true;
                            }
                          }
                          if (!isFoundTopic) {
                            Topic topic = new Topic(tid, tag_name, 1);
                            topics.add(topic);
                          }
                        } else {
                          Topic topic = new Topic(tid, tag_name, 1);
                          List<Topic> list = new ArrayList<>();
                          list.add(topic);
                          stgInfo.getTopic().put(cid, list);
                        }
                      } else {
                        Map<Integer, List<Topic>> topicMap = new HashMap<>();
                        List<Topic> topicList = new ArrayList<>();
                        Topic topic = new Topic(tid, tag_name, 1);
                        topicList.add(topic);
                        topicMap.put(cid, topicList);
                        stgInfo.setTopic(topicMap);
                      }
                    }
                  }
                }
                //是否stype筛选项
                if (!isFoundSTG) {
                  for (int s : lightZSKU.type2) {
                    if(vTypeFilters.containsKey(s)) {
                      Set<Integer> set = vTypeFilters.get(s);
                      if (set.contains(cid)) {
                        //获取stgId
                        List<Integer> listSTG = neMap.get(s);
                        for (int stgId : listSTG) {
                          if (vTypeMap.containsKey(stgId)) {
                            if (vTypeMap.get(stgId).contains(s)) {
                              STGInfo stgInfo = aggregationProduct.getStg_info().get(stgId);
                              if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                                Map<Integer, List<Topic>> topicMap = stgInfo.getTopic();
                                if (topicMap.containsKey(cid)) {
                                  List<Topic> topics = stgInfo.getTopic().get(cid);
                                  boolean isFoundTopic = false;
                                  for (Topic topic : topics) {
                                    if (topic.getId() == tid) {
                                      topic.incSize();
                                      isFoundTopic = true;
                                    }
                                  }
                                  if (!isFoundTopic) {
                                    Topic topic = new Topic(tid, tag_name, 1);
                                    topics.add(topic);
                                  }
                                } else {
                                  Topic topic = new Topic(tid, tag_name, 1);
                                  List<Topic> list = new ArrayList<>();
                                  list.add(topic);
                                  stgInfo.getTopic().put(cid, list);
                                }
                              } else {
                                Map<Integer, List<Topic>> topicMap = new HashMap<>();
                                List<Topic> topicList = new ArrayList<>();
                                Topic topic = new Topic(tid, tag_name, 1);
                                topicList.add(topic);
                                topicMap.put(cid, topicList);
                                stgInfo.setTopic(topicMap);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        //统计国家城市，poi
      /*
      Tag tag;
      Set<String> countries = new HashSet<>();
      Set<String> cities = new HashSet<>();
      Set<String> continent = new HashSet<>();
      List<Poi> pois = new ArrayList<>();

      List<Map<String, Object>> listedTags = (List<Map<String, Object>>) dataMap.get(FIELD_TAGS);
      if (CollectionUtils.isNotEmpty(listedTags)) {
        for (Map<String, Object> map : listedTags) {
          tag = Tag.buildTag(map);
          if (tag == null) {
            continue;
          }
          //是否目的地，是否poi
          String name = tag.getTagName();
          if(tag.getTagType() == TagType.CITY){
            cities.add(name);
          }else if(tag.getTagType() == TagType.COUNTRY){
            countries.add(name);
          }else if(tag.getTagType() == TagType.CONTINENT){
            continent.add(name);
          }else if(TagType.POI == tag.getTagType()){
            int tgid = tag.getId();
            pois.add(new Poi(tgid, name, 1));
          }
        }
      }
      //统计
      Map<String, Country> countryMap = new HashMap<>();
      Map<String,List<String>> city_country_map = MutableCaches.getInstance().CITY_COUNTRY_MAP_ALL.getCacheContent();
      Map<String,Integer> cityInfo = MutableCaches.getInstance().CITIES.getCacheContent();
      Map<String,Integer> countryInfo = MutableCaches.getInstance().COUNTRIES.getCacheContent();
      Map<String,String> ccMap = MutableCaches.getInstance().COUNTRY_CONTINENT_MAP.getCacheContent();

      if(StringUtils.isEmpty(countryStr)){
        if(StringUtils.isEmpty(cityStr)){
          List<String> cyList = new ArrayList<>(cities);
          for(String str:countries){
            int countryId = countryInfo.get(str);
            int conid = Constants.CONTINENT_MAP.get(ccMap.get(str));
            List<City> cityList = new ArrayList<>();
            Country country = new Country(countryId, str, conid, cityList, 1);
            for(int i = 0; i < cyList.size(); i++){
              String cityName = cyList.get(i);
              List<String> countryNames = city_country_map.get(cityName);
              if(countryNames.contains(str)){
                int cityId = cityInfo.get(cityName);
                City city = new City(cityId, cityName, 1);
                country.add(city);
                cities.remove(cityName);
              }
            }
            //
            for(int tp1:lightZSKU.type1){
              if(aggregationProduct.getStg_info().containsKey(tp1)){
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for(Country country1:countryList){
                    if(country1.equals(country)){
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if(!isFoundCou){
                    countryList.add(country);
                  }
                }else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
          //剩余城市
          if(CollectionUtils.isNotEmpty(cities)){

            int countryId = 11;
            int conId = 10;
            List<City> cityList = new ArrayList<>();
            Country country = new Country(countryId, "中国", conId, cityList, 1);

            for(String str:cities){
              List<String> countryNames = city_country_map.get(str);
              if(countryNames.contains("中国")){
                int a = cityInfo.get(str);
                City city = new City(a, str, 1);
                country.add(city);
                continue;
              }
            }

            for(int tp1:lightZSKU.type1){
              if(aggregationProduct.getStg_info().containsKey(tp1)){
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for(Country country1:countryList){
                    if(country1.equals(country)){
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if(!isFoundCou){
                    countryList.add(country);
                  }
                }else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
        }else {
          int cityId = cityInfo.get(cityStr);
          List<String> cnys = city_country_map.get(cityStr);
          for(String cny:cnys){
            if(countries.contains(cny)){
              City city = new City(cityId, cityStr, 1);
              List<City> cityList = new ArrayList<>();
              int countryId = countryInfo.get(cny);
              int conid = Constants.CONTINENT_MAP
                .get(ccMap.get(cny));
              Country country = new Country(countryId, cny, conid, cityList, 1);

              for(int tp1:lightZSKU.type1){
                if(aggregationProduct.getStg_info().containsKey(tp1)){
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for(Country country1:countryList){
                      if(country1.equals(country)){
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if(!isFoundCou){
                      countryList.add(country);
                    }
                  }else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }else if("中国".equals(cny)){
              City city = new City(cityId, cityStr, 1);
              List<City> cityList = new ArrayList<>();
              int countryId = 11;
              int conid = 10;
              Country country = new Country(countryId, cny, conid, cityList, 1);
              for(int tp1:lightZSKU.type1){
                if(aggregationProduct.getStg_info().containsKey(tp1)){
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for(Country country1:countryList){
                      if(country1.equals(country)){
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if(!isFoundCou){
                      countryList.add(country);
                    }
                  }else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }
          }
        }
      }else {
        int ccid = countryInfo.get(countryStr);
        int conid = Constants.CONTINENT_MAP
          .get(ccMap.get(countryStr));
        if(StringUtils.isEmpty(cityStr)){
          List<City> cityList = new ArrayList<>();
          Country country = new Country(ccid, countryStr, conid, cityList, 1);
          for(String cty:cities){
            List<String> couns = city_country_map.get(cty);
            if(couns.contains(countryStr)){
              City city = new City(cityInfo.get(cty), cty, 1);
              country.add(city);
            }
          }
          //
          for(int tp1:lightZSKU.type1){
            if(aggregationProduct.getStg_info().containsKey(tp1)){
              STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
              if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                boolean isFoundCou = false;
                List<Country> countryList = stgInfo.getCountry();
                for(Country country1:countryList){
                  if(country1.equals(country)){
                    country1.add(country);
                    isFoundCou = true;
                    break;
                  }
                }
                if(!isFoundCou){
                  countryList.add(country);
                }
              }else {
                List<Country> countryList = new ArrayList<>();
                countryList.add(country);
                stgInfo.setCountry(countryList);
              }
            }
          }
          //
        }else {
          City city = new City(cityInfo.get(cityStr), cityStr, 1);
          List<City> cityList = new ArrayList<>();
          Country country = new Country(ccid, countryStr, conid, cityList,1);
          for(int tp1:lightZSKU.type1){
            if(aggregationProduct.getStg_info().containsKey(tp1)){
              STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
              if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                boolean isFoundCou = false;
                List<Country> countryList = stgInfo.getCountry();
                for(Country country1:countryList){
                  if(country1.equals(country)){
                    country1.add(country);
                    isFoundCou = true;
                    break;
                  }
                }
                if(!isFoundCou){
                  countryList.add(country);
                }
              }else {
                List<Country> countryList = new ArrayList<>();
                countryList.add(country);
                stgInfo.setCountry(countryList);
              }
            }
          }
        }
      }*/
        //start_city_id
        try {
          List<Map<String, Object>> listedCity = (List<Map<String, Object>>) dataMap
            .get(FIELD_CITIES);
          if (CollectionUtils.isNotEmpty(listedCity)) {
            //System.out.println("START_CITY for lid:" + lightZSKU.id);
            for (Map<String, Object> map : listedCity) {
              com.qyer.search.model.City city = com.qyer.search.model.City.buildCity(map);
              City newCity = new City(city.getId(), city.getPlaceName(), 1);
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  List<City> cityList = stgInfo.getStart_city_id();
                  if (CollectionUtils.isNotEmpty(cityList)) {
                    boolean isFound = false;
                    for (City city1 : cityList) {
                      if (city1.equals(newCity)) {
                        city1.add(newCity);
                        isFound = true;
                        break;
                      }
                    }
                    if (!isFound) {
                      cityList.add(newCity);
                    }
                  } else {
                    List<City> list = new ArrayList<>();
                    list.add(newCity);
                    stgInfo.setStart_city_id(list);
                  }
                }
              }
            }
          }
        }catch (Exception e){
          e.printStackTrace();
          System.out.println(e.toString());
        }
        //travelday
        //System.out.println("LightZSKU build day");
        try {
          int day = cast2Int(dataMap.get(FIELD_TRAVELDAY));
          if (day > 0) {
            TravelDay travelDay = new TravelDay(day, 1);
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                List<TravelDay> travelDays = stgInfo.getTravelDays();
                if (CollectionUtils.isNotEmpty(travelDays)) {
                  boolean isFound = false;
                  for (TravelDay td : travelDays) {
                    if (td.equals(travelDay)) {
                      td.add(travelDay);
                      isFound = true;
                      break;
                    }
                  }
                  if (!isFound) {
                    travelDays.add(travelDay);
                  }
                } else {
                  List<TravelDay> list = new ArrayList<>();
                  list.add(travelDay);
                  stgInfo.setTravelDays(list);
                }
              }
            }
          }
        }catch (Exception e){
          e.printStackTrace();
          System.out.println("E"+e.toString());
        }
        //abroad
        //System.out.println("FIELD_SOURCE_PLACE go");
        List<Map<String, Object>> listedAbroad = (List<Map<String, Object>>) dataMap
          .get(FIELD_SOURCE_PLACE);
        if (CollectionUtils.isNotEmpty(listedAbroad)) {
          //System.out.println("FIELD_SOURCE_PLACE");
          for (Map<String, Object> map : listedAbroad) {
            com.qyer.search.model.SetOutPlace setOutPlace = com.qyer.search.model.SetOutPlace
              .buildPlace(map);
            SetOutPlace setOutPlace1 = new SetOutPlace(Constants.START_POS_MAP_INVERS_NAME
                                                         .get(setOutPlace
                                                                .getId()), setOutPlace.getPlace(), 1);
            //System.out.println("SETOUT"+setOutPlace1.toString());
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                List<SetOutPlace> cityList = stgInfo.getAbroad();
                if (CollectionUtils.isNotEmpty(cityList)) {
                  boolean isFound = false;
                  for (SetOutPlace city1 : cityList) {
                    if (city1.equals(setOutPlace1)) {
                      city1.add(setOutPlace1);
                      isFound = true;
                      break;
                    }
                  }
                  if (!isFound) {
                    cityList.add(setOutPlace1);
                  }
                } else {
                  List<SetOutPlace> list = new ArrayList<>();
                  list.add(setOutPlace1);
                  stgInfo.setAbroad(list);
                }
              }
            }
          }
        }else {
          //System.out.println("set out place null id :" + lightZSKU.id);
        }
        //title
        //System.out.println("JIOOIPPDA");
      }
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("D"+e.toString());
    }
    return lightZSKU;
  }



  public static LightZSKU build_NO(SearchParameterEntity spe, Map<String, Object> dataMap,
                                   List<AbstractFilter> filters, AggregationRegular regular,
                                   AggregationProduct aggregationProduct){
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }

    //System.out.println("LightZSKU build");
    int id = cast2Int(dataMap.get(FIELD_ID));
    LightZSKU lightZSKU = build(id);
    AbstractValidator validator = MutableCaches.getInstance().SKU_AVAILABILITY_VALIDATOR
      .getCacheContent();
    if (!validator.isValid(spe, id)) {
      return null;
    }
    if(filters != null) {
      for (int i = 0; i < filters.size(); i++) {
        if (!filters.get(i).isValid(dataMap, spe))
          return null;
      }
    }
    List<LightZSKU> lightZSKUs = new ArrayList<>();
    int market_info = Integer.MAX_VALUE;
    Map<Integer, Set<Integer>> vTypeMap = regular.getvTypeMap();
    Map<Integer, Set<Integer>> vTypeFilters = regular.getvTypeFilters();
    Map<Integer, Set<Integer>> vGTypeFilters = regular.getvGTypeFilters();
    String cityStr = regular.getCity();
    String countryStr = regular.getCountry();
    String continentName = regular.getContinent();
    //System.out.println("continentName:"+continentName);
    //

    lightZSKU.setMarket_info(market_info);
    String ztitle = cast2String(dataMap.get(FIELD_TITLE));
    lightZSKU.setTitle(ztitle);

    //
    int channel = regular.getChannel();
    Set<Integer> stypeChannel = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent()
                                                                          .getvStypeMap().get(channel).getS_type_set();
    Set<Integer> vtypeSet = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent()
                                                                      .getvStypeMap().get(
        channel).getS_type_set();
    Map<Integer,List<Integer>> neMap = MutableCaches.getInstance().Z_TAG_SNAPSHOT
      .getCacheContent().getvStypeMap().get(channel).getNegativeMap();
    Map<Integer, Integer> filterValues = MutableCaches.getInstance().Z_TAG_SNAPSHOT.getCacheContent().getFilterValues();
    Set<Integer> market_tag_Set = MutableCaches.getInstance().Z_TAG_SNAPSHOT
      .getCacheContent().getvStypeMap().get(channel).getMarket_tag_Set();
    //获取styoe
    //System.out.println("LightZSKU build ztag");
    Set<Integer> integerSet = new HashSet<>();
    int count166 = 0;
    ZTag zTag;
    List<Map<String, Object>> listedData = (List<Map<String, Object>>) dataMap.get(FIELD_Z_TAGS);
    try {
      if (CollectionUtils.isNotEmpty(listedData)) {
        for (Map<String, Object> map : listedData) {
          zTag = ZTag.buildTag(map);
          if (zTag == null) {
            continue;
          }
          if (zTag.getChannel() != channel) {
            if (zTag.getChannel() != -1) {
              continue;
            }
          }
          String tag_name = zTag.getTag_name();
          int tid = zTag.getTid();
          int zchannel = zTag.getChannel();


          //stg
          if (zchannel > 0) {
            if (!vTypeMap.containsKey(tid)) {
              continue;
            } else {
              if(!lightZSKU.getType1().contains(tid)){
                lightZSKU.type1(tid);
                if (aggregationProduct != null) {
                  if (aggregationProduct.getStg_info().containsKey(tid)) {
                    aggregationProduct.getStg_info().get(tid).setName(tag_name);
                    aggregationProduct.getStg_info().get(tid).incSize();
                    if(tid == 166){
                      count166 ++;
                    }
                    //System.out.println("aggregationProduct +1");
                  } else {
                    STGInfo stgInfo = new STGInfo(1, tag_name);
                    aggregationProduct.getStg_info().put(tid, stgInfo);
                  }
                }
              }
              /*lightZSKU.type1(tid);
              if (aggregationProduct != null) {
                if (aggregationProduct.getStg_info().containsKey(tid)) {
                  aggregationProduct.getStg_info().get(tid).setName(tag_name);
                  aggregationProduct.getStg_info().get(tid).incSize();
                  if(tid == 166){
                    count166 ++;
                  }
                  //System.out.println("aggregationProduct +1");
                } else {
                  STGInfo stgInfo = new STGInfo(1, tag_name);
                  aggregationProduct.getStg_info().put(tid, stgInfo);
                }
              }*/
            }
          } else {
            //非stg
            if (vtypeSet.contains(tid)) {
              List<Integer> list = neMap.get(tid);
              for (int gt : list) {
                if (vTypeMap.containsKey(gt)) {
                  Set<Integer> set = vTypeMap.get(gt);
                  if (set.contains(tid)) {
                    lightZSKU.type2(tid);
                    if (aggregationProduct != null) {
                      if (aggregationProduct.getStg_info().containsKey(gt)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(gt);
                        if (CollectionUtils.isNotEmpty(stgInfo.getS_type())) {
                          boolean isFound = false;
                          for (VStype vStype : stgInfo.getS_type()) {
                            if (vStype.getId() == tid) {
                              isFound = true;
                              vStype.incSize();
                              break;
                            }
                          }
                          if (!isFound) {
                            VStype vStype = new VStype(tid, tag_name, 1);
                            stgInfo.getS_type().add(vStype);
                          }
                        } else {
                          VStype vStype = new VStype(tid, tag_name, 1);
                          List<VStype> stypes = new ArrayList<>();
                          stypes.add(vStype);
                          stgInfo.setS_type(stypes);
                        }
                      } else {
                        STGInfo stgInfo = new STGInfo(0, null);
                        aggregationProduct.getStg_info().put(gt, stgInfo);
                        VStype vStype = new VStype(tid, tag_name, 1);
                        List<VStype> stypes = new ArrayList<>();
                        stypes.add(vStype);
                        stgInfo.setS_type(stypes);
                      }
                    }
                  }
                }
              }
            } else {
              //运营
              if (market_tag_Set.contains(tid)) {
                lightZSKU.setMarket_info(Integer.valueOf(tag_name.trim()));
                //System.out.println("运营:" + lightZSKU.id + ":级别:" + lightZSKU.getMarket_info());
              }
            }
          }

        }
      } else {
        return null;
      }
    }catch (Exception e){
      e.printStackTrace();
      //System.out.println("A" + e.toString());
    }

    if(count166 > 1){
      //System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++~~~~~~~~ID:"+lightZSKU.id+"~~~Size:"+count166);
    }

    if(CollectionUtils.isEmpty(lightZSKU.getType1())){
      //System.out.println("NO STG lid:" + lightZSKU.id);
      return null;
    }

    //System.out.println("LightZSKU build TAG");
    //Tag
    Tag tag;
    Set<String> countries = new HashSet<>();
    Set<String> cities = new HashSet<>();
    Set<String> continent = new HashSet<>();
    Set<Poi> pois = new HashSet<>();

    List<Map<String, Object>> listedTags = (List<Map<String, Object>>) dataMap.get(FIELD_TAGS);
    try {
      if (CollectionUtils.isNotEmpty(listedTags)) {
        for (Map<String, Object> map : listedTags) {
          tag = Tag.buildTag(map);
          if (tag == null) {
            continue;
          }
          lightZSKU.addTag(tag);
          if (tag.forExternalize()) {
            lightZSKU.addExternalizedTag(tag);
          }
          //是否目的地，是否poi
          String name = tag.getTagName();
          /*if (tag.getTagType() == TagType.CITY) {
            cities.add(name);
          } else if (tag.getTagType() == TagType.COUNTRY) {
            countries.add(name);
          } else if (tag.getTagType() == TagType.CONTINENT) {
            continent.add(name);
          } else if (TagType.POI == tag.getTagType()) {
            int tgid = tag.getId();
            pois.add(new Poi(tgid, name, 1));
          }*/

          TagStatus status = tag.getStatus();
          if(TagStatus.ENABLE == status) {
            if (tag.getTagType() == TagType.CITY) {
              cities.add(name);
            } else if (tag.getTagType() == TagType.COUNTRY) {
              countries.add(name);
            } else if (tag.getTagType() == TagType.CONTINENT) {
              continent.add(name);
            } else if (TagType.POI == tag.getTagType()) {
              int tgid = tag.getId();
              pois.add(new Poi(tgid, name, 1));
            }
          }
        }
      }
    }catch (Exception e){
      e.printStackTrace();
      //System.out.println("B"+ e.toString());
    }
    ////////////////////////////////////////////
    ////////////////////////////////////////////
    //统计
    try {
      if (aggregationProduct != null) {
        //System.out.println("聚合目的地");
        Map<String, Country> countryMap = new HashMap<>();
        Map<String, List<String>> city_country_map = MutableCaches
          .getInstance().CITY_COUNTRY_MAP_ALL.getCacheContent();
        Map<String, Integer> cityInfo = MutableCaches.getInstance().CITIES.getCacheContent();
        Map<String, Integer> countryInfo = MutableCaches.getInstance().COUNTRIES.getCacheContent();
        Map<String, String> ccMap = MutableCaches.getInstance().COUNTRY_CONTINENT_MAP
          .getCacheContent();

        if (StringUtils.isEmpty(countryStr)) {
          if (StringUtils.isEmpty(cityStr)) {
            List<String> cyList = new ArrayList<>(cities);
            for (String str : countries) {
              int countryId = countryInfo.get(str);
              //////////////////////////////////////////////////
              if(!ccMap.containsKey(str)){
                //System.out.println("CCMAP MISS "+ str);
                continue;
              }
              String continentStr = ccMap.get(str);
              if(continentName != null) {
                if (!continentStr.equals(continentName)) {
                  continue;
                }
              }
              if(!Constants.CONTINENT_MAP.containsKey(continentStr)){
                //System.out.println("CONTINENT_MAP MISS "+ continentStr);
                continue;
              }
              //////////////////////////////////////////////////
              int conid = Constants.CONTINENT_MAP.get(ccMap.get(str));
              List<City> cityList = new ArrayList<>();
              Country country = new Country(countryId, str, conid, cityList, 1);
              for (int i = 0; i < cyList.size(); i++) {
                String cityName = cyList.get(i);
                if(city_country_map.containsKey(cityName)) {
                  List<String> countryNames = city_country_map.get(cityName);
                  if (countryNames.contains(str)) {
                    int cityId = cityInfo.get(cityName);
                    City city = new City(cityId, cityName, 1);
                    country.add(city);
                    //System.out.println("country add city:" + cityName);
                    cities.remove(cityName);
                  }
                }else {
                  //System.out.println("NOT MATCH CITY:" + cityName);
                }
              }
              //
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for (Country country1 : countryList) {
                      if (country1.equals(country)) {
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if (!isFoundCou) {
                      countryList.add(country);
                    }
                  } else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }
            //剩余城市
            if (CollectionUtils.isNotEmpty(cities)) {
              //System.out.println("剩余城市:"+cities);
              int countryId = 11;
              int conId = 10;
              List<City> cityList = new ArrayList<>();
              Country country = new Country(countryId, "中国", conId, cityList, 1);
              List<String> leftCity = new ArrayList<>(cities);
              for (String str : leftCity) {
                //System.out.println("1剩余城市:"+str);
                if(city_country_map.containsKey(str)) {
                  List<String> countryNames = city_country_map.get(str);
                  //System.out.println("2剩余城市国家list:"+countryNames);
                  if (countryNames.contains("中国")) {
                    //System.out.println("其他城市中国成功 "+ str);
                    int a = cityInfo.get(str);
                    City city = new City(a, str, 1);
                    country.add(city);

                  }
                }
              }

              if(country.getCity().size() > 1) {
                for (int tp1 : lightZSKU.type1) {
                  if (aggregationProduct.getStg_info().containsKey(tp1)) {
                    STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                    if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                      boolean isFoundCou = false;
                      List<Country> countryList = stgInfo.getCountry();
                      for (Country country1 : countryList) {
                        if (country1.equals(country)) {
                          country1.add(country);
                          isFoundCou = true;
                          break;
                        }
                      }
                      if (!isFoundCou) {
                        countryList.add(country);
                      }
                    } else {
                      List<Country> countryList = new ArrayList<>();
                      countryList.add(country);
                      stgInfo.setCountry(countryList);
                    }
                  }
                }//
              }
            }
          } else {
            int cityId = cityInfo.get(cityStr);
            if(!"台湾".equals(cityStr)) {
              if (city_country_map.containsKey(cityStr)) {
                List<String> cnys = city_country_map.get(cityStr);
                for (String cny : cnys) {
                  if (countries.contains(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    cityList.add(city);
                    int countryId = countryInfo.get(cny);
                    int conid = Constants.CONTINENT_MAP.get(ccMap.get(cny));
                    Country country = new Country(countryId, cny, conid, cityList, 1);

                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  } else if ("中国".equals(cny)) {
                    City city = new City(cityId, cityStr, 1);
                    List<City> cityList = new ArrayList<>();
                    cityList.add(city);
                    int countryId = 11;
                    int conid = 10;
                    Country country = new Country(countryId, cny, conid, cityList, 1);
                    for (int tp1 : lightZSKU.type1) {
                      if (aggregationProduct.getStg_info().containsKey(tp1)) {
                        STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                        if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                          boolean isFoundCou = false;
                          List<Country> countryList = stgInfo.getCountry();
                          for (Country country1 : countryList) {
                            if (country1.equals(country)) {
                              country1.add(country);
                              isFoundCou = true;
                              break;
                            }
                          }
                          if (!isFoundCou) {
                            countryList.add(country);
                          }
                        } else {
                          List<Country> countryList = new ArrayList<>();
                          countryList.add(country);
                          stgInfo.setCountry(countryList);
                        }
                      }
                    }
                  }
                }
              }//////
            }else {
              Set<String> taiwans = new HashSet<>(MutableCaches.getInstance().TAIWAN_MAP.getCacheContent());
              taiwans.remove("台湾");

              List<City> cityList = new ArrayList<>();
              int countryId = 11;
              int conid = 10;
              //boolean isFind = false;
              /////////////
              int idCityT = cityInfo.get(cityStr);
              City cityT = new City(idCityT, cityStr, 1);
              cityList.add(cityT);
              /////////////
              Country country = new Country(countryId, "中国", conid, cityList, 1);
              for(String cityName:cities){
                if(!cityName.equals("台湾")) {
                  if (taiwans.contains(cityName)) {
                    int idCity = cityInfo.get(cityName);
                    City city = new City(idCity, cityName, 1);
                    cityList.add(city);
                  }
                }
              }
              /*
              if(cityList.size() == 0){
                int idCity = cityInfo.get(cityStr);
                System.out.println("台湾List:"+cityStr);
                City city = new City(idCity, cityStr, 1);
                cityList.add(city);
              }*/
              /////
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for (Country country1 : countryList) {
                      if (country1.equals(country)) {
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if (!isFoundCou) {
                      countryList.add(country);
                    }
                  } else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }
          }/////
        } else {
          int ccid = countryInfo.get(countryStr);
          int conid = Constants.CONTINENT_MAP.get(ccMap.get(countryStr));
          if (StringUtils.isEmpty(cityStr)) {
            List<City> cityList = new ArrayList<>();
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            for (String cty : cities) {
              if(!city_country_map.containsKey(cty)){
                //System.out.println("city:"+cty);
              }else {
                if(city_country_map.containsKey(cty)) {
                  List<String> couns = city_country_map.get(cty);
                  if (couns.contains(countryStr)) {
                    if (cityInfo.containsKey(cty)) {
                      City city = new City(cityInfo.get(cty), cty, 1);
                      country.add(city);
                    }
                  }
                }
              }
            }
            //
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
            //
          } else {
            City city = new City(cityInfo.get(cityStr), cityStr, 1);
            List<City> cityList = new ArrayList<>();
            cityList.add(city);
            Country country = new Country(ccid, countryStr, conid, cityList, 1);
            if("台湾".equals(cityStr)){
              Set<String> taiwans = new HashSet<>(MutableCaches.getInstance().TAIWAN_MAP.getCacheContent());
              for(String cityName:cities){
                if(!cityName.equals("台湾")) {
                  if (taiwans.contains(cityName)) {
                    int idCity1 = cityInfo.get(cityName);
                    City city1 = new City(idCity1, cityName, 1);
                    cityList.add(city1);
                  }
                }
              }
            }
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if (CollectionUtils.isNotEmpty(stgInfo.getCountry())) {
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for (Country country1 : countryList) {
                    if (country1.equals(country)) {
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if (!isFoundCou) {
                    countryList.add(country);
                  }
                } else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
        }
        //poi
        for (int tp1 : lightZSKU.type1) {
          if (aggregationProduct.getStg_info().containsKey(tp1)) {
            STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
            if (CollectionUtils.isNotEmpty(stgInfo.getPoi())) {
              boolean isFoundCou = false;
              List<Poi> poiList = stgInfo.getPoi();
              List<Poi> poiList1 = new ArrayList<>(poiList);
              for (Poi poi1 : pois) {
                for (Poi poi : poiList1) {
                  if (poi1.equals(poi)) {
                    poi.add(poi1);
                    isFoundCou = true;
                    break;
                  }
                }
                if (!isFoundCou) {
                  poiList.add(poi1);
                }
              }
            }else{
              List<Poi> poiList = new ArrayList<>(pois);
              stgInfo.setPoi(poiList);
            }
          }
        }
      }
      //////////////////////////////////////////////////////
    }catch (Exception e){
      e.printStackTrace();
      //System.out.println("C"+e.toString());
    }
    //---------------------------------------------------------------------------------------------//
    try {
      if (aggregationProduct != null) {
        for (Map<String, Object> map : listedData) {
          zTag = ZTag.buildTag(map);
          if (zTag == null) {
            continue;
          }
          if (zTag.getChannel() != channel) {
            if (zTag.getChannel() != -1) {
              continue;
            }
          }
          String tag_name = zTag.getTag_name();
          int tid = zTag.getTid();
          int zchannel = zTag.getChannel();

          if (zchannel < 0) {
            if (filterValues.containsKey(tid)) {
              //筛选项
              if (aggregationProduct != null) {
                int cid = filterValues.get(tid);
                boolean isFoundSTG = false;
                for (int s : lightZSKU.type1) {
                  if(vGTypeFilters.containsKey(s)) {
                    Set<Integer> set = vGTypeFilters.get(s);
                    if (set.contains(cid)) {
                      isFoundSTG = true;
                      STGInfo stgInfo = aggregationProduct.getStg_info().get(s);
                      if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                        if (stgInfo.getTopic().containsKey(cid)) {
                          List<Topic> topics = stgInfo.getTopic().get(cid);
                          boolean isFoundTopic = false;
                          for (Topic topic : topics) {
                            if (topic.getId() == tid) {
                              topic.incSize();
                              isFoundTopic = true;
                            }
                          }
                          if (!isFoundTopic) {
                            Topic topic = new Topic(tid, tag_name, 1);
                            topics.add(topic);
                          }
                        } else {
                          Topic topic = new Topic(tid, tag_name, 1);
                          List<Topic> list = new ArrayList<>();
                          list.add(topic);
                          stgInfo.getTopic().put(cid, list);
                        }
                      } else {
                        Map<Integer, List<Topic>> topicMap = new HashMap<>();
                        List<Topic> topicList = new ArrayList<>();
                        Topic topic = new Topic(tid, tag_name, 1);
                        topicList.add(topic);
                        topicMap.put(cid, topicList);
                        stgInfo.setTopic(topicMap);
                      }
                    }
                  }
                }
                //是否stype筛选项
                if (!isFoundSTG) {
                  for (int s : lightZSKU.type2) {
                    if(vTypeFilters.containsKey(s)) {
                      Set<Integer> set = vTypeFilters.get(s);
                      if (set.contains(cid)) {
                        //获取stgId
                        List<Integer> listSTG = neMap.get(s);
                        for (int stgId : listSTG) {
                          if (vTypeMap.containsKey(stgId)) {
                            if (vTypeMap.get(stgId).contains(s)) {
                              STGInfo stgInfo = aggregationProduct.getStg_info().get(stgId);
                              if (MapUtils.isNotEmpty(stgInfo.getTopic())) {
                                Map<Integer, List<Topic>> topicMap = stgInfo.getTopic();
                                if (topicMap.containsKey(cid)) {
                                  List<Topic> topics = stgInfo.getTopic().get(cid);
                                  boolean isFoundTopic = false;
                                  for (Topic topic : topics) {
                                    if (topic.getId() == tid) {
                                      topic.incSize();
                                      isFoundTopic = true;
                                    }
                                  }
                                  if (!isFoundTopic) {
                                    Topic topic = new Topic(tid, tag_name, 1);
                                    topics.add(topic);
                                  }
                                } else {
                                  Topic topic = new Topic(tid, tag_name, 1);
                                  List<Topic> list = new ArrayList<>();
                                  list.add(topic);
                                  stgInfo.getTopic().put(cid, list);
                                }
                              } else {
                                Map<Integer, List<Topic>> topicMap = new HashMap<>();
                                List<Topic> topicList = new ArrayList<>();
                                Topic topic = new Topic(tid, tag_name, 1);
                                topicList.add(topic);
                                topicMap.put(cid, topicList);
                                stgInfo.setTopic(topicMap);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        //统计国家城市，poi
      /*
      Tag tag;
      Set<String> countries = new HashSet<>();
      Set<String> cities = new HashSet<>();
      Set<String> continent = new HashSet<>();
      List<Poi> pois = new ArrayList<>();

      List<Map<String, Object>> listedTags = (List<Map<String, Object>>) dataMap.get(FIELD_TAGS);
      if (CollectionUtils.isNotEmpty(listedTags)) {
        for (Map<String, Object> map : listedTags) {
          tag = Tag.buildTag(map);
          if (tag == null) {
            continue;
          }
          //是否目的地，是否poi
          String name = tag.getTagName();
          if(tag.getTagType() == TagType.CITY){
            cities.add(name);
          }else if(tag.getTagType() == TagType.COUNTRY){
            countries.add(name);
          }else if(tag.getTagType() == TagType.CONTINENT){
            continent.add(name);
          }else if(TagType.POI == tag.getTagType()){
            int tgid = tag.getId();
            pois.add(new Poi(tgid, name, 1));
          }
        }
      }
      //统计
      Map<String, Country> countryMap = new HashMap<>();
      Map<String,List<String>> city_country_map = MutableCaches.getInstance().CITY_COUNTRY_MAP_ALL.getCacheContent();
      Map<String,Integer> cityInfo = MutableCaches.getInstance().CITIES.getCacheContent();
      Map<String,Integer> countryInfo = MutableCaches.getInstance().COUNTRIES.getCacheContent();
      Map<String,String> ccMap = MutableCaches.getInstance().COUNTRY_CONTINENT_MAP.getCacheContent();

      if(StringUtils.isEmpty(countryStr)){
        if(StringUtils.isEmpty(cityStr)){
          List<String> cyList = new ArrayList<>(cities);
          for(String str:countries){
            int countryId = countryInfo.get(str);
            int conid = Constants.CONTINENT_MAP.get(ccMap.get(str));
            List<City> cityList = new ArrayList<>();
            Country country = new Country(countryId, str, conid, cityList, 1);
            for(int i = 0; i < cyList.size(); i++){
              String cityName = cyList.get(i);
              List<String> countryNames = city_country_map.get(cityName);
              if(countryNames.contains(str)){
                int cityId = cityInfo.get(cityName);
                City city = new City(cityId, cityName, 1);
                country.add(city);
                cities.remove(cityName);
              }
            }
            //
            for(int tp1:lightZSKU.type1){
              if(aggregationProduct.getStg_info().containsKey(tp1)){
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for(Country country1:countryList){
                    if(country1.equals(country)){
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if(!isFoundCou){
                    countryList.add(country);
                  }
                }else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
          //剩余城市
          if(CollectionUtils.isNotEmpty(cities)){

            int countryId = 11;
            int conId = 10;
            List<City> cityList = new ArrayList<>();
            Country country = new Country(countryId, "中国", conId, cityList, 1);

            for(String str:cities){
              List<String> countryNames = city_country_map.get(str);
              if(countryNames.contains("中国")){
                int a = cityInfo.get(str);
                City city = new City(a, str, 1);
                country.add(city);
                continue;
              }
            }

            for(int tp1:lightZSKU.type1){
              if(aggregationProduct.getStg_info().containsKey(tp1)){
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                  boolean isFoundCou = false;
                  List<Country> countryList = stgInfo.getCountry();
                  for(Country country1:countryList){
                    if(country1.equals(country)){
                      country1.add(country);
                      isFoundCou = true;
                      break;
                    }
                  }
                  if(!isFoundCou){
                    countryList.add(country);
                  }
                }else {
                  List<Country> countryList = new ArrayList<>();
                  countryList.add(country);
                  stgInfo.setCountry(countryList);
                }
              }
            }
          }
        }else {
          int cityId = cityInfo.get(cityStr);
          List<String> cnys = city_country_map.get(cityStr);
          for(String cny:cnys){
            if(countries.contains(cny)){
              City city = new City(cityId, cityStr, 1);
              List<City> cityList = new ArrayList<>();
              int countryId = countryInfo.get(cny);
              int conid = Constants.CONTINENT_MAP
                .get(ccMap.get(cny));
              Country country = new Country(countryId, cny, conid, cityList, 1);

              for(int tp1:lightZSKU.type1){
                if(aggregationProduct.getStg_info().containsKey(tp1)){
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for(Country country1:countryList){
                      if(country1.equals(country)){
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if(!isFoundCou){
                      countryList.add(country);
                    }
                  }else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }else if("中国".equals(cny)){
              City city = new City(cityId, cityStr, 1);
              List<City> cityList = new ArrayList<>();
              int countryId = 11;
              int conid = 10;
              Country country = new Country(countryId, cny, conid, cityList, 1);
              for(int tp1:lightZSKU.type1){
                if(aggregationProduct.getStg_info().containsKey(tp1)){
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                    boolean isFoundCou = false;
                    List<Country> countryList = stgInfo.getCountry();
                    for(Country country1:countryList){
                      if(country1.equals(country)){
                        country1.add(country);
                        isFoundCou = true;
                        break;
                      }
                    }
                    if(!isFoundCou){
                      countryList.add(country);
                    }
                  }else {
                    List<Country> countryList = new ArrayList<>();
                    countryList.add(country);
                    stgInfo.setCountry(countryList);
                  }
                }
              }
            }
          }
        }
      }else {
        int ccid = countryInfo.get(countryStr);
        int conid = Constants.CONTINENT_MAP
          .get(ccMap.get(countryStr));
        if(StringUtils.isEmpty(cityStr)){
          List<City> cityList = new ArrayList<>();
          Country country = new Country(ccid, countryStr, conid, cityList, 1);
          for(String cty:cities){
            List<String> couns = city_country_map.get(cty);
            if(couns.contains(countryStr)){
              City city = new City(cityInfo.get(cty), cty, 1);
              country.add(city);
            }
          }
          //
          for(int tp1:lightZSKU.type1){
            if(aggregationProduct.getStg_info().containsKey(tp1)){
              STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
              if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                boolean isFoundCou = false;
                List<Country> countryList = stgInfo.getCountry();
                for(Country country1:countryList){
                  if(country1.equals(country)){
                    country1.add(country);
                    isFoundCou = true;
                    break;
                  }
                }
                if(!isFoundCou){
                  countryList.add(country);
                }
              }else {
                List<Country> countryList = new ArrayList<>();
                countryList.add(country);
                stgInfo.setCountry(countryList);
              }
            }
          }
          //
        }else {
          City city = new City(cityInfo.get(cityStr), cityStr, 1);
          List<City> cityList = new ArrayList<>();
          Country country = new Country(ccid, countryStr, conid, cityList,1);
          for(int tp1:lightZSKU.type1){
            if(aggregationProduct.getStg_info().containsKey(tp1)){
              STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
              if(CollectionUtils.isNotEmpty(stgInfo.getCountry())){
                boolean isFoundCou = false;
                List<Country> countryList = stgInfo.getCountry();
                for(Country country1:countryList){
                  if(country1.equals(country)){
                    country1.add(country);
                    isFoundCou = true;
                    break;
                  }
                }
                if(!isFoundCou){
                  countryList.add(country);
                }
              }else {
                List<Country> countryList = new ArrayList<>();
                countryList.add(country);
                stgInfo.setCountry(countryList);
              }
            }
          }
        }
      }*/
        //start_city_id
        try {
          List<Map<String, Object>> listedCity = (List<Map<String, Object>>) dataMap
            .get(FIELD_CITIES);
          if (CollectionUtils.isNotEmpty(listedCity)) {
            //System.out.println("START_CITY for lid:" + lightZSKU.id);
            for (Map<String, Object> map : listedCity) {
              com.qyer.search.model.City city = com.qyer.search.model.City.buildCity(map);
              City newCity = new City(city.getId(), city.getPlaceName(), 1);
              for (int tp1 : lightZSKU.type1) {
                if (aggregationProduct.getStg_info().containsKey(tp1)) {
                  STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                  List<City> cityList = stgInfo.getStart_city_id();
                  if (CollectionUtils.isNotEmpty(cityList)) {
                    boolean isFound = false;
                    for (City city1 : cityList) {
                      if (city1.equals(newCity)) {
                        city1.add(newCity);
                        isFound = true;
                        break;
                      }
                    }
                    if (!isFound) {
                      cityList.add(newCity);
                    }
                  } else {
                    List<City> list = new ArrayList<>();
                    list.add(newCity);
                    stgInfo.setStart_city_id(list);
                  }
                }
              }
            }
          }
        }catch (Exception e){
          e.printStackTrace();
          System.out.println(e.toString());
        }
        //travelday
        //System.out.println("LightZSKU build day");
        try {
          int day = cast2Int(dataMap.get(FIELD_TRAVELDAY));
          if (day > 0) {
            TravelDay travelDay = new TravelDay(day, 1);
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                List<TravelDay> travelDays = stgInfo.getTravelDays();
                if (CollectionUtils.isNotEmpty(travelDays)) {
                  boolean isFound = false;
                  for (TravelDay td : travelDays) {
                    if (td.equals(travelDay)) {
                      td.add(travelDay);
                      isFound = true;
                      break;
                    }
                  }
                  if (!isFound) {
                    travelDays.add(travelDay);
                  }
                } else {
                  List<TravelDay> list = new ArrayList<>();
                  list.add(travelDay);
                  stgInfo.setTravelDays(list);
                }
              }
            }
          }
        }catch (Exception e){
          e.printStackTrace();
          System.out.println("E"+e.toString());
        }
        //abroad
        //System.out.println("FIELD_SOURCE_PLACE go");
        List<Map<String, Object>> listedAbroad = (List<Map<String, Object>>) dataMap
          .get(FIELD_SOURCE_PLACE);
        if (CollectionUtils.isNotEmpty(listedAbroad)) {
          //System.out.println("FIELD_SOURCE_PLACE");
          for (Map<String, Object> map : listedAbroad) {
            com.qyer.search.model.SetOutPlace setOutPlace = com.qyer.search.model.SetOutPlace
              .buildPlace(map);
            SetOutPlace setOutPlace1 = new SetOutPlace(Constants.START_POS_MAP_INVERS_NAME
                                                         .get(setOutPlace
                                                                .getId()), setOutPlace.getPlace(), 1);
            //System.out.println("SETOUT"+setOutPlace1.toString());
            for (int tp1 : lightZSKU.type1) {
              if (aggregationProduct.getStg_info().containsKey(tp1)) {
                STGInfo stgInfo = aggregationProduct.getStg_info().get(tp1);
                List<SetOutPlace> cityList = stgInfo.getAbroad();
                if (CollectionUtils.isNotEmpty(cityList)) {
                  boolean isFound = false;
                  for (SetOutPlace city1 : cityList) {
                    if (city1.equals(setOutPlace1)) {
                      city1.add(setOutPlace1);
                      isFound = true;
                      break;
                    }
                  }
                  if (!isFound) {
                    cityList.add(setOutPlace1);
                  }
                } else {
                  List<SetOutPlace> list = new ArrayList<>();
                  list.add(setOutPlace1);
                  stgInfo.setAbroad(list);
                }
              }
            }
          }
        }else {
          //System.out.println("set out place null id :" + lightZSKU.id);
        }
        //title
        //System.out.println("JIOOIPPDA");
      }
    }catch (Exception e){
      e.printStackTrace();
      System.out.println("D"+e.toString());
    }
    return lightZSKU;
  }
}



/*
if (!isFoundSTG) {
                  for (int s : lightZSKU.type2) {
                    if(vTypeFilters.containsKey(s)) {
                      Set<Integer> set = vTypeFilters.get(s);
                      if (set.contains(cid)) {
                        //获取stgId
                        List<Integer> listSTG = neMap.get(tid);
                        for (int stgId : listSTG) {
                          if (vTypeMap.containsKey(stgId)) {
                            if (vTypeMap.get(stgId).contains(tid)) {
                              STGInfo stgInfo = aggregationProduct.getStg_info().get(stgId);
                              if (stgInfo.getTopic() != null) {
                                Map<Integer, List<Topic>> topicMap = stgInfo.getTopic();
                                if (topicMap.containsKey(cid)) {
                                  List<Topic> topics = stgInfo.getTopic().get(cid);
                                  boolean isFoundTopic = false;
                                  for (Topic topic : topics) {
                                    if (topic.getId() == tid) {
                                      topic.incSize();
                                      isFoundTopic = true;
                                    }
                                  }
                                  if (!isFoundTopic) {
                                    Topic topic = new Topic(tid, tag_name, 1);
                                    topics.add(topic);
                                  }
                                } else {
                                  Topic topic = new Topic(tid, tag_name, 1);
                                  List<Topic> list = new ArrayList<>();
                                  list.add(topic);
                                  stgInfo.getTopic().put(cid, list);
                                }
                              } else {
                                Map<Integer, List<Topic>> topicMap = new HashMap<>();
                                List<Topic> topicList = new ArrayList<>();
                                Topic topic = new Topic(tid, tag_name, 1);
                                topicList.add(topic);
                                topicMap.put(cid, topicList);
                                stgInfo.setTopic(topicMap);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
                */
